Multidimensional Arrays need help, please CSC110AA/AB and cl Ch 7 Activity 3 Mul
ID: 3819278 • Letter: M
Question
Multidimensional Arrays need help, please
CSC110AA/AB and cl Ch 7 Activity 3 Multidimensional Arrays In this activity you will be exploring features of 2 dimensional arrays. These arrays are commonly viewed as rows and columns. An array called myExams keeps track of quiz scores for 10 students Each student has 3 quiz scores. The array in this activity could be represented like this: 1. Download the starting file ArrayActivity2D.java. 2. Complete as directed by the comments in the file. Rows [3] 3. Submit your completed code. [8] Expected output: Display the array 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 The sum of the array: 435.0 Challenge: Calculate the average The average is 14.5 Challenge Count how many values that are greater than 22: Number of values greater than 22: 7 Columns [0] [1] [2]Explanation / Answer
public class ArrayActivity2D{
public static void main(String[] args)
{
double value = 0.0;
double sum = 0.0;
double average = 0.0;
int countValues = 0;
//Declare an array calledmyExams that keeps track of exm scores for 10 students.
//Each student has 3 quiz scores.
double[][] myExams = new double[10][3];
//load the array with the values 0 - 29, in order
value = 0;
for(int i=0;i<10;i++){
for(int j=0;j<3;j++){
myExams[i][j]=value;
value++;
}
}
// display all the components of the array
System.out.println("Display the array ");
for(int i=0;i<10;i++){
for(int j=0;j<3;j++){
System.out.print(myExams[i][j]+" ");
}
System.out.print(" ");
}
// add up all the element values in the array
sum = 0.0;
for(int i=0;i<10;i++){
for(int j=0;j<3;j++){
sum=sum+myExams[i][j];
}
}
System.out.println("The sum of the array: " + sum);
// challenge : calculate the average
average=sum/30;
System.out.println(" Challenge: Calculate the average ");
System.out.println("The average is :" + average);
System.out.println(" Challenge: Count how many values that are greater than 22: ");
countValues = 0;
for(int i=0;i<10;i++){
for(int j=0;j<3;j++){
if(myExams[i][j]>22){
countValues++;
}
}
}
System.out.println("Number of values greater than 22: " + countValues);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.