w3resource
Java Programming Exercies

Java Array Exercises: Print the specified grid

Java Array: Exercise-3 with Solution

Write a Java program to print the following grid.

Sample Solution:

Java Code:

public class Main {
public static void main(String[] args) {   
 int [][]a = new int[10][10];    
 for(int i = 0; i < 10; i++)
   {
      for(int j = 0; j < 10; j++)
      {
         System.out.printf("%2d ", a[i][j]);
      }
      System.out.println();
   }
}
}

Sample Output:

0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 
 0  0  0  0  0  0  0  0  0  0 

Flowchart:

Flowchart: Java exercises: Print the specified grid

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a Java program to sum values of an array.
Next: Write a Java program to calculate the average value of array elements.



New Content: Composer: Dependency manager for PHP, R Programming