(In Java)
1. Create a 6X6 2D Array called numCourses
2. Sum the rows and print out the results with text identifying
what you are outputting.
3. Sum the columns and print out the results with text identifying
what you are outputting.
4. Compare the rows output and calculate and output the minimum
value and maximum value.
*/
public class TwoDArrayExamplesHW{
public static void main(String[] args){
int[][] numCourses = {{2, 3, 2, 0, 0},
{2, 3, 2, 3, 1},
{0, 2, 0, 2, 0},
{1, 1, 1, 1, 1}};
for(int col = 0; col < numCourses[0].length; col++){
int sum = 0;
for(int row = 0; row < numCourses.length; row++){
sum += numCourses[row][col];
}
System.out.println("Total is " + sum);
}
}
}
public class Main { // main function public static void main(String[] args) { int[][] numCourses = {{2, 3, 2, 0, 0, 4}, {2, 3, 2, 3, 1, 0}, {0, 2, 0, 2, 0, 2}, {1, 1, 1, 1, 1, 1}, {3, 0, 2, 1, 4, 2}, {5, 4, 1, 3, 4, 2}}; // display sum of rows for(int row = 0; row < numCourses[0].length; row++){ int sum = 0; for(int col = 0; col < numCourses.length; col++){ sum += numCourses[row][col]; } System.out.println("Sum of row " + (row + 1) + " is: " + sum); } System.out.println(); // display sum of columns for(int col = 0; col < numCourses[0].length; col++){ int sum = 0; for(int row = 0; row < numCourses.length; row++){ sum += numCourses[row][col]; } System.out.println("Sum of column " + (col + 1) + " is: " + sum); } System.out.println(); // display total sum int total = 0; for(int col = 0; col < numCourses[0].length; col++){ for(int row = 0; row < numCourses.length; row++){ total += numCourses[row][col]; } } System.out.println("Total is sum of array is: " + total); System.out.println(); // find minimum and maximum of array int min = numCourses[0][0]; int max = numCourses[0][0]; for(int row = 0; row < numCourses[0].length; row++){ for(int col = 0; col < numCourses.length; col++){ if(min > numCourses[row][col]) { min = numCourses[row][col]; } if(max < numCourses[row][col]) { max = numCourses[row][col]; } } } System.out.println(); System.out.println("The minimum value in array is: " + min); System.out.println("The maximum value in array is: " + max); } }
FOR HELP PLEASE COMMENT.
THANK YOU
Get Answers For Free
Most questions answered within 1 hours.