Page 301 - Computer science 868 Class 12
P. 301

1.  Integer data types:
                   a.  int ar[][] = new int[2][4]; creates an array of integer data type
                   b.  long ar[][] = new long[2][4];  creates an array of long data type
                   c.  short ar[][] = new short[2][4];  creates an array of short data type
                   d.  byte ar[][] = new byte[2][4];  creates an array of byte data type
                 2.  Real data types:
                   a.  float ar[][] = new float[2][4];  creates an array of float data type

                   b.  double ar[][] = new double[2][4];  creates an array of double datat ype
                 3.  Character data type:
                      char ar[][] = new char[2][4];  creates an array of character data type
                 Like single-dimensional arrays, in double-dimensional array values can be entered in four different ways.
                 Let us see in detail.

                 1.  Static way: By using Assignment Statements
                   a.  int ar[][] = {{1,2,3},{4,5,6},{6,7,8}};
                   b.  double ar[][] = {{1.2,3.4},{1.4,3.2}};
                   c.  char ar[][] = {{'a','r'},{'1','4'},{',','='}};

                   d.  String ar[][] = {{"India, "New Delhi"},{"America","Washington,D.C"}};
                 2.  Dynamic Way:
                 Here, Scanner class will be used. Different methods of Scanner class such as nextInt(), nextDouble(), etc are required
                 for entering data.



                   Program 13    Write a program to accept numbers into a m × n matrix. Display the original matrix and
                                 convert the matrix in transpose form.


                   1       // Transpose a Matrix //
                   2       import java.util.*;
                   3       class transpose

                   4       {
                   5           public static void main()

                   6           {
                   7               Scanner sc= new Scanner(System.in);

                   8               int i,j,m,n,t;
                   9

                   10              System.out.print("Enter the number of rows and columns : ");
                   11              m=sc.nextInt();

                   12              n=sc.nextInt();
                   13              int a[][]=new int[m][n];

                   14              for(i = 0;i<m;i++)





                                                                                                                       299
                                                                                                              Arrays   299
   296   297   298   299   300   301   302   303   304   305   306