For Java , Use for loops to fill in a 2-D array called grid2 that contains  the following data (Note this is an array with 7 rows and 9 columns!): // 1 2 3 4 5 6 7 8 9 // 9 8 7 6 5 4 3 2 1 // 1 2 3 4 5 6 7 8 9 // 9 8 7 6 5 4 3 2 1 // 1 2 3 4 5 6 7 8 9 // 9 8 7 6 5 4 3 2 1 // 1 2 3 4 5 6 7 8 9

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 11RQ
icon
Related questions
Question

For Java , Use for loops to fill in a 2-D array called grid2 that contains
 the following data (Note this is an array with 7 rows and 9 columns!):

// 1 2 3 4 5 6 7 8 9
// 9 8 7 6 5 4 3 2 1
// 1 2 3 4 5 6 7 8 9
// 9 8 7 6 5 4 3 2 1
// 1 2 3 4 5 6 7 8 9
// 9 8 7 6 5 4 3 2 1
// 1 2 3 4 5 6 7 8 9

Expert Solution
Code:

class Test99 {
 public static void main(String args[]) {
  int grid2[][] = new int[7][9];
  int i, j;
  
  for(i = 0; i < 7; i++) {
   for(j = 0; j < 9; j++) {
    if(i % 2 == 0)
     grid2[i][j] = (j + 1);
    else
     grid2[i][j] = (9 - j);
   }
  }
  
  for(i = 0; i < 7; i++) {
   for(j = 0; j < 9; j++) {
    System.out.print(grid2[i][j] + " ");
   }
   System.out.println();
  }
 }
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT