radko93

macierz

Feb 7th, 2013
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.FileReader;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class macierz {
  7.     int[][] tab;
  8.     public void wczytaj()
  9.     {
  10.         try {
  11.             Scanner sc = new Scanner(new FileReader("/Users/radek/Desktop/elo.txt"));
  12.             int wierszy = sc.nextInt();
  13.             int kolumn = sc.nextInt();
  14.             tab = new int[wierszy][kolumn];
  15.             //for(int i = 0; i < wierszy*kolumn; i++)
  16.             //{
  17.             //  tab[(int)Math.floor((double)i/(double)kolumn)][i % kolumn] = sc.nextInt();
  18.             //}
  19.             for(int i = 0; i < tab.length; i++)
  20.                 for(int j = 0; j < tab[i].length; j++)
  21.                     tab[i][j] = sc.nextInt();
  22.                                                                 } catch (FileNotFoundException e) {
  23.             // TODO Auto-generated catch block
  24.             e.printStackTrace();
  25.         }
  26.     }
  27.     public void wyswietl()
  28.     {
  29.         for(int i = 0; i < tab.length; i++)
  30.         {
  31.             for(int j = 0; j < tab[i].length; j++)
  32.             {
  33.                 System.out.printf("%d ", tab[i][j]);
  34.             }
  35.             System.out.printf("%n");
  36.         }
  37.     }
  38.     public static void main(String[] args) {
  39.         // TODO Auto-generated method stub
  40. macierz t= new macierz();
  41. t.wczytaj();
  42. t.wyswietl();
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment