Page 318 - Cs_withBlue_J_C11_Flipbook
P. 318
22 {
23 System.out.println("Cube of the number "+ ar[i][j] + " is: "
+ ((int)Math.pow(ar[i][j],3)));
24 }
25 }
26 }
27 }
28 }
The output of the preceding program is as follows:
Enter a number: 3
Enter a number: 4
Enter a number: 6
Enter a number: 7
Enter a number: 5
Enter a number: 8
Cube of the number 4 is: 64
Cube of the number 6 is: 216
Cube of the number 8 is: 512
Dynamic Way: Using InputStreamReader
This is another technique to insert the values by accepting the values from the user.
Program 19 Accept numbers into a 3 × 3 array and then calculate the sum of even numbers present in
odd positions.
1 import java.io.*;
2 class sum
3 {
4 public static void main() throws IOException
5 {
6 InputStreamReader isr = new InputStreamReader(System.in);
7 BufferedReader br= new BufferedReader(isr);
8 int n[ ][ ] = new int[3][3];
9 int i, j, s=0;
10 for(i = 0;i<3; i++)
11 {
12 for(j= 0; j<3; j++)
13 {
316316 Touchpad Computer Science-XI

