Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2D arrays then solve the Write the following Java methods and test it in the main() method. 1- Write a method printArray() to display the


2D arrays then solve the Write the following Java methods and test it in the main() method.

  1. 1- Write a method printArray() to display the elements of a two-dimensional array of integers. The array is received as a parameter.
    public static void printArray(int [][] arr)
    Create a 2D array in the main method, call it array1, that is 10 rows and 5 columns and print it.

  2. 2- Write a method fillArray() to initialize a two-dimensional array of integers to random values. The integer array is received as a parameter. The initialization values are generated randomly between a minimum and a maximum value.
    public static void fillArray(int [][] arr, int min, int max)

    Fill the array created in 1 (array1) with values between 10 and 100

  3. 3- Write a method to determine if a two dimensional array is square or not. The method returns

    true if the number of rows is equal to the number of columns of the 2D array

    public static boolean isSquare(int [][] arr)

    Test your method with the created array array1.

    Create another array, call it array2, that has 5 rows and 5 columns, then fill it and test again.

  4. 4- Write a method to determine and display the sum of all the values in the primary diagonal of a 2D

    integer array. The 2D integer array is received as a parameter to the method.

    public static int sumOfPrimary(int [][] arr)

    In the main method, get and display the sum of primary for array2.

  5. 5- Write a method to determine and display the sum of all the values in the secondary diagonal of a

    2D integer array. The 2D integer array is received as a parameter to the method.

    public static int sumOfSecondary(int [][] arr)

    In the main method, get and display the sum of secondary for array2.

  6. 6- Write a method to find the sum of each row in a 2-dimensional integer array. The return value is

    an array of integers.

    public static int[] sumofRows (int [][] arr)

    In the main method, get and display the sum of rows for both array1 and array2.

  7. 7- Write a method to find the sum of each column in a 2-dimensional array. The return value is an

    array of integers.

    public static int[] sumOfCol(int [][] arr)

    In the main method, get and display the sum of columns for both array1 and array2.

Step by Step Solution

3.47 Rating (144 Votes )

There are 3 Steps involved in it

Step: 1

CODE import javautilRandom public class TwoDimensionalArrays public static void mainString args Create a 2D array in the main method call it array1 that is 10 rows and 5 columns and print it int array... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Accounting questions