Advertisement
Guest User

namkitomar

a guest
Mar 30th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class Array2D {
  2. public static void main(String[] args) {
  3. int[][] myArray = new int[12][8];
  4. int numRows = myArray.length;
  5. int numCols = myArray[0].length;
  6.  
  7. for (int row = 0; row < numRows; ++row) {
  8. for (int col = 0; col < numCols; ++col) {
  9. myArray[row][col] = row * numCols + col + 1;
  10. }
  11. }
  12.  
  13. for (int row = 0; row < numRows; ++row) {
  14. for (int col = 0; col < numCols; ++col) {
  15. System.out.printf("%3d", myArray[row][col]);
  16. }
  17. System.out.println();
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement