Question

(In Java) 1. Create a 6X6 2D Array called numCourses 2. Sum the rows and print...

(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);

}

}

}

Homework Answers

Answer #1
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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
DESCRIPTION: You will be given a 2D array, called matrix, of Strings. The array has an...
DESCRIPTION: You will be given a 2D array, called matrix, of Strings. The array has an unknown number of cells filled with data. Your goal is to iterate through the 2D array and keep a count of how many cells are full. You will be given the dimensions of the array. INPUT: All input has been handled for you: Two integers denoting the dimensions of the array. These are the integer variables rows and cols. A partially filled 2-D array....
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
Write a method called sumDiagonal() that takes a 2D array of int as an argument returns...
Write a method called sumDiagonal() that takes a 2D array of int as an argument returns the sum of the first element in the first row, the second element of the second row, the third element of the third row, etc. You may assume that the array is not jagged and has at least as many columns as rows.
(This is for Java) For this I need to make a loop that will sum the...
(This is for Java) For this I need to make a loop that will sum the numbers from 3 to 22 public class Practice25 {    public static void main (String [] args) {            int sum = 0;           //The loop will go here      sum += i;     System.out.println ("Sum from 3 to 22 is: " + sum);    } }
IN JAVA Print "userNum1 is negative." if userNum1 is less than 0. End with newline. Convert...
IN JAVA Print "userNum1 is negative." if userNum1 is less than 0. End with newline. Convert userNum2 to 0 if userNum2 is greater than 10. Otherwise, print "userNum2 is less than or equal to 10.". End with newline. public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; userNum1 = 0; userNum2 = 7; *insert* System.out.println("userNum2 is " + userNum2); } }
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Please use my template import java.util.Scanner; public class...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...