Professional Documents
Culture Documents
Arrays Are Used To Store Multiple Values in A Single Variable, Instead of Declaring Separate Variables For Each Value
Arrays Are Used To Store Multiple Values in A Single Variable, Instead of Declaring Separate Variables For Each Value
0 1 2 3 4 5 6 7 8 9
2 4 6 7 8 1 2 4 5 6
import java.util.*;
for(int i=0;i<3;i++)
Problem #2: Total the number of
{
elements larger than 5. for(int j=0;j<3;j++) {
System.out.print("Enter a number:");
a[i][j]=sc.nextInt();
}} //end of outer loop
sc.close();
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++){
sum = sum+a[i][j];
}} //end of outer loop
System.out.print(sum);
}}
Problem #2: Rotate It
Sample Run
Problem Description: My phone, it’s stuck! It doesn’t seem to Enter the number of rows: 3
rotate anymore. I have this multidimensional array whose Enter the number of columns: 4
values I need to rotate in order to properly decipher. If it doesn’t 3 6 2 4
rotate 90 degrees clockwise, then I’m in big trouble! Help! 9 3 2 1
5 3 2 1
Input/Output Rotated:
1. Number of rows of the multidimensional array 5 9 3
2. Number of columns of the multidimensional array 3 3 6
3. Elements of the multidimensional array 2 2 2
1 1 4