Menu
Coddy logo textTech

Recap - All About Arrays

Part of the Logic & Flow section of Coddy's Java journey — lesson 9 of 59.

challenge icon

Challenge

Easy

Create a method named arrayOperations that takes a 2D array of integers (matrix) as input and performs the following operations:

  1. Calculate the sum of all elements in the matrix.
  2. Find the maximum element in the matrix.
  3. Create a new 1D array that contains the sums of each row in the matrix.
  4. Print to the console using the following format:
Sum: 78
Maximum: 12
Row Sums: [10, 26, 42]

Try it yourself

import java.util.Arrays;

// Write your code only inside the class. Do not write main() or any code outside this class.
class ArrayOperations {
    public static void arrayOperations(int[][] matrix) {
        // Write your code here
    
    
        System.out.println("Sum: " + sum);
        System.out.println("Maximum: " + max);
        System.out.println("Row Sums: " + Arrays.toString(rowSums));

    }
}

All lessons in Logic & Flow