Filling 2D
an anonymous user
·
Java
import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
int currentIndex = 27;
int[][] array = new int[10][10];
for (int i = 0; i < array.length; i++) {
for (int j = i; j <= i + 2 && (j < array[i].length); j++) {
array[i][j] = currentIndex--;
}
}
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length; j++) {
System.out.print((array[j][i] > 9 ? "" : " ") + array[j][i] + " ");
}
System.out.println();
}
}
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.