Advertisement
Shavit

P. 121 Ex. 12.2

Mar 2nd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args)
  9.     {
  10.         Scanner in = new Scanner(System.in);
  11.         int rows;
  12.         int cols;
  13.        
  14.         System.out.printf("How many rows does your array have? ");
  15.         rows = in.nextInt();
  16.        
  17.         System.out.printf("How many coloumns does your array have? ");
  18.         cols = in.nextInt();
  19.        
  20.         ArrIni array = new ArrIni(rows, cols);
  21.         array.printTable();
  22.         in.close();
  23.     }
  24. }
  25.  
  26. // Next class
  27.  
  28. public class ArrIni
  29. {
  30.     int[][] array;
  31.    
  32.     public ArrIni(int rows, int cols)
  33.     {
  34.         array = new int[rows][cols];
  35.         for(int i = 0; i < array.length; i++)
  36.             for(int j = 0; j < array[i].length; j++)
  37.                 array[i][j] = j + (i * 10);
  38.     }
  39.    
  40.     public void printTable()
  41.     {
  42.         for(int i = 0; i < array.length; i++)
  43.         {
  44.             for(int j = 0; j < array[i].length; j++)
  45.                 System.out.printf("%d\t", array[i][j]);
  46.             System.out.printf("\n");
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement