Question
int k; System.out.print(Enter the value of rows: ); int R = kb.nextInt(); System.out.print(Enter the value of cols: ); int C = kb.nextInt(); for(int i =
int k; System.out.print("Enter the value of rows: "); int R = kb.nextInt(); System.out.print("Enter the value of cols: "); int C = kb.nextInt(); for(int i = 1; i<=R; i++){ k = ?; //Q1: what to start at each line-i? System.out.print(k); for(int j=0; j; j++){ //Q2: How many times to repat the pattern of ', k'? k+=R; System.out.print(", "+k); } System.out.println(); }
and displays a comma-separated grid of numbers where R represents the number of rows and C represents the number of columns. The output will display in column-major order (see in the assignment printGrid.java). The numbers shown increase sequentially down each column and wrap to the top of the next column to the right once the bottom of the current column is reached. Assume both R and C are positive (>0). For instance, if the user enters a 3 for R and 1 for C, your program should display:
1 2 3 If the user enters a 4 for R and 3 for C, your program should display:
1, 5, 9 2, 6, 10 3, 7, 11 4, 8, 12
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started