Advertisement
MrDoyle

12) Multidimensional Arrays

Jan 14th, 2021
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         int [] values = {3, 5, 7645};
  6.         System.out.println(values[2]);
  7.  
  8.         int [][] grid = {
  9.                 {3, 5, 7645},
  10.                 {2, 4},
  11.                 {1, 2, 3, 4}
  12.         };
  13.  
  14.         System.out.println(grid [2][3]);
  15.         System.out.println(grid [0][1]);
  16.  
  17.  
  18.         String [][] texts = new String [2][3];
  19.         System.out.println(texts[0][1]);
  20.  
  21.         texts[0][1] = "Hello there";
  22.         System.out.println(texts[0][1]);
  23.  
  24.  
  25.         for (int row = 0 ; row<grid.length; row++){
  26.             for (int col = 0; col < grid[row].length; col++){
  27.                 System.out.print(grid[row][col] + " \t");
  28.             }
  29.             System.out.println();
  30.         }
  31.  
  32.  
  33.         String[][] words = new String[2][];
  34.         System.out.println(words[0]);
  35.  
  36.         words[0] = new String [3];
  37.         words[0][1] = "hi there";
  38.         System.out.println(words[0][1]);
  39.  
  40.         System.out.println(words[1]);
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement