Page 317 - Cs_withBlue_J_C11_Flipbook
P. 317
14 System.out.println();
15 }
16 }
17 }
The output of the preceding program is as follows:
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 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 array_cube_even
3 {
4 public static void main()
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 {
11 for (j=0; j<3; j++)
12 {
13 System.out.print("Enter a number: ");
14 ar[i][j] =sc.nextInt();
15 }
16 }
17 for (i=0; i<2; i++) //Loop to input values in array
18 {
19 for (j=0; j<3; j++)
20 {
21 if(ar[i][j] %2==0)
315
Arrays 315

