Question: write a java code take a sum of each column and make sure its aligned and crerate a new column call Average and Calculate the
write a java code take a sum of each column and make sure its aligned and crerate a new column call "Average" and Calculate the quiz averages for below code.
//This program calculates student quiz totals and class quiz averages.
import java.util.Scanner;
public class StudentQuiz {
public static void main(String[] args){
// (HW10) Create a 2-dimensional array for 10 student grades on 5 quizzes
int[][] studGrade = new int[10][5];
// (HW10) Generate random integer grades (0-10) for all students in all quizzes
for (int row = 0; row < studGrade.length; row++) {
for (int column = 0; column < studGrade[row].length; column++){
studGrade[row][column] = (int)(Math.random() * 10);
}
}
// Array initializer
// int [][] studGrade = {
// {7, 8, 6, 8, 9},
// {8, 9, 8, 7, 9},
// {9, 9, 7, 6, 7},
// {8, 9, 6, 7, 8},
// {7, 8, 9, 9, 9},
// {6, 9, 6, 8, 7},
// {9, 8, 7, 8, 7},
// {8, 8, 9, 8, 7},
// {8, 5, 8, 9, 6},
// {7, 6, 9, 7, 9}
// };
// Print the student quiz table
//Quiz heads
System.out.println("Studs# | Q1 | Q2 | Q3 | Q4 | Q5 | Total |");
//Separator
System.out.println("---------------------------------------------");
// For loop for rows
for ( int row = 0; row < studGrade.length; row++){
// stud #:
System.out.printf("Stud%2d |", (row + 1));
// for loop for elements in the row.
int total = 0;
for ( int column = 0; column < studGrade[row].length; column++){
System.out.printf(" %2d |", studGrade[row][column]);
total += studGrade[row][column];
}
// row total
System.out.printf(" %5d | ", total);
}
// take a sum of each column and make sure its aligned.
// crerate a new column call "Average" and Calculate the quiz averages
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
