Question: GridPractice.java coding: import java.util.Scanner; import java.util.Random; public class GridPractice { public static void main(String[] args) { //declarations Scanner in = new Scanner(System.in); Random generator =

 GridPractice.java coding: import java.util.Scanner; import java.util.Random; public class GridPractice { publicstatic void main(String[] args) { //declarations Scanner in = new Scanner(System.in); Randomgenerator = new Random(); int [][] grid; //un-instantiated grid int size =

GridPractice.java coding:

import java.util.Scanner;

import java.util.Random;

public class GridPractice {

public static void main(String[] args) {

//declarations

Scanner in = new Scanner(System.in);

Random generator = new Random();

int [][] grid; //un-instantiated grid

int size = 0; /umber of rows and columns

//get size of grid - no validation & instantiate

System.out.print("Enter size of grid: ");

size = in.nextInt();

grid = new int[size][size];

//fill grid with random number from 1..99

System.out.println();

for (int row=0; row

for (int col=0; col

grid[row][col] = generator.nextInt(100); //random numbers 0.99 - not 100

}

}

//STEP 3(exercise 1): print grid with formatting to align

//STEP 4A (exercise 2): print each row sum

//STEP 4B (exercise 2): print each column sum

//STEP 5 (exercise 3): print two diagonal sums

}

}

Lab 10: 2-Dimensional Arrays Note: All Exercises must be completed during the lab period. Exercise 1- Grid sums (5 points) 1. Download the file GridPractice.zip from myCourses that unzips to a file named GridPractice.java. There are no other classes as all code will be in the main method. After the user enters a size, the program creates a 2-dimensional array (named grid) with the size to specify the number of rows and columns. To avoid typing a great deal of input, the program stores random numbers between 0.. 99 into each position in grid. 2. . Write the code to print the contents of the gridas shown in the Sample Output. To have the columns align, you will need to use the printf command. When the program works correctly, have the instructor or TA check the code and initialize. Have instructor or TA sign here when Exercise 1 works correctly. Exercise 2- Row and Column Sums (3 points) 4 Write the code to calculate and print the sum of each row and each column. (See Example). Have instructor or TA sign here when Exercise 2 works correctly. Exercise 3- Diagonal Sums (2 points) Write the code to calculate and print the sum of the two diagonals. Assume that the size is 3. One diagonal starts in the upper left corner [0] [0])and ends in the lower right corner ( [2] [2]). The other diagonal starts in the upper right corner ([0] [2]) and end in the lower left corner ([2] [0]) 5. Have instructor or TA sign here when Exercise 3 works correctly

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!