Page 356 - ComputerScience_Class_11
P. 356

5               int i, j;
                 6           int marks[ ][ ]={{67,87,89,79},{99,34,56,87},{45,87,69,80},{67,89,78,98}};

                 7               System.out.println("Number of marks: "+ (marks.length*marks.length));
                 8               for(i=0; i<4; i++)
                 9               {
                10                   for(j=0; j<4; j++)
                11                   {
                12                       System.out.print(marks[i][j]+"\t");
                13                   }
                14                   System.out.println();

                15               }
                16           }
                17       }
              The output of the preceding program is as follows:

                      BlueJ: Terminal Window - Java
                   Options

                  Number of marks: 16
                  67     87     89     79
                  99     34     56     87
                  45     87     69     80
                  67     89     78     98




              Dynamic Way: Using Scanner Class
              In this method, the Scanner class is used to take in input from the user.



                Program 18     Write a Java program to create a two-dimensional array of size 2 × 3 and print the cube of all
                               the even numbers in the array.
                 1       import java.util.*;

                 2       class CubeOfEvenNumbers
                 3       {

                 4
                             public static void main(String args[])
                 5           {
                 6               Scanner sc= new Scanner(System.in);

                 7               int ar[ ][ ]=new int[2][3];
                 8               int i, j;

                 9               for (i=0; i<2; i++)
                10               {






                  354  Touchpad Computer Science (Ver. 3.0)-XI
   351   352   353   354   355   356   357   358   359   360   361