Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. package lab3;
  2.  
  3. /**
  4.  *
  5.  * @author user
  6.  */
  7. public class Lab3 {
  8.  
  9.     /**
  10.      * @param args the command line arguments
  11.      */
  12.     public static void main(String[] args) {
  13.        
  14.         Przykl1 przyklad1 = new Przykl1();
  15.         Przykl2 przyklad2 = new Przykl2();
  16.        
  17.     }
  18.    
  19. }
  20.  
  21. class Przykl1
  22. {
  23.     public Przykl1()
  24.             {
  25.                 int x,y;
  26.                 int[][] a = { {1,2}, {3, 4}};
  27.                 int b[][] = { {1,2}, {3}, {} };
  28.                
  29.                 a[0][0] = 0;
  30.                 x = a[1][1];
  31.                
  32.                
  33.                 System.out.println("Wartość elementu o indeksach 1,1 tablicy a to "+x);
  34.                 y = b.length;
  35.                 System.out.println("Rozmiar tablicy b to "+y);
  36.                 y = b[0].length;
  37.                 System.out.println("Rozmiar pierwszego wiersza tablicy b to "+y);
  38.                 y = b[1].length;
  39.                 System.out.println("Rozmiar drugiego wiersza tablicy b to "+y);
  40.                 y = b[2].length;
  41.                 System.out.println("Rozmiar trzeciego wiersza tablicy b to "+y);
  42.                
  43.             }
  44. }
  45.  
  46. class Przykl2
  47. {
  48.     public Przykl2()
  49.             {
  50.                 int tab[][] = new int [5][];
  51.                
  52.                 tab[0] = new int [4];
  53.                 tab[1] = new int [3];
  54.                 tab[2] = new int [2];
  55.                 tab[3] = new int [1];                
  56.                 tab[4] = new int [4];
  57.  
  58.                  int i,j;
  59.                  
  60.                  for(i=0; i<tab.length; i++)
  61.                  {
  62.                      for(j=0; j<tab[i].length; j++)
  63.                      {
  64.                          tab[i][j] = (int)(100*Math.random());
  65.                      }
  66.                  }
  67.                  
  68.                   for(i=0; i<tab.length; i++)
  69.                  {
  70.                      for(j=0; j<tab[i].length; j++)
  71.                      {
  72.                          System.out.print(tab[i][j]+"\t");
  73.                          System.out.println();
  74.                      }
  75.                  }  
  76.                
  77.             }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement