Question: JAVA Assignment Ask the user to enter the size of an array (int value) Allocate a 2D array of int that size (if the user

JAVA Assignment

  • Ask the user to enter the size of an array (int value)
  • Allocate a 2D array of int that size (if the user enters in 5, then allocate a 5x5 array)
  • Using a Random, initialize each element of the array to be either 0 or 1
  • Output the array in a table format (see below for an example)
  • Output the fraction of your array that is ones and the fraction that is zeros. For example, suppose the user asked for a 3x3 array and after initialization, that array happened to contain 4 ones and 5 zeros. The fraction of ones would be 4/9 and the fraction of zeros would be 5/9.
  • Calculate and output the sum of each row. Output the index of the largest row sum.
  • Calculate and output the sum of each column. Output the index of the largest column sum.
  • Out rows win if the largest row sum is greater than the largest column sum. Otherwise, output columns win
  • Calculate the diagonal sum. Use the diagonal starting at location [0][0] and going down to [N-1][N-1] for an array of size N.
  • Output diagonals rule if the diagonal sum is greater or equal to the largest row sum and greater than or equal to the largest column sum.
  • There is an example shown below
  • JAVA Assignment Ask the user to enter the size of an array

Run #1: my name is Bob McStudent enter the size of the array... 0110 1100 1111 0011 fraction of ones = 10/16 fraction of zeros = 6/16 row 0 sum = 2 row 1 sum = 2 row 2 sum = 4 row 3 sum = 2 row 2 has the largest row sum! col O sum = 2 col 1 sum = 3 col 2 sum = 3 col 3 sum = 2 col 1 has the largest col sum! rows win! diagonal sum is 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!