radko93 icon

macierz

radko93 | PRO | 02/07/13 09:01:04 AM UTC | 0 ⭐ | 228 👁️ | Never ⏰ | []
Java |

1.07 KB

|

None

|

0 👍

/

0 👎

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
 
 
public class macierz {
    int[][] tab;
    public void wczytaj()
    {
        try {
            Scanner sc = new Scanner(new FileReader("/Users/radek/Desktop/elo.txt"));
            int wierszy = sc.nextInt();
            int kolumn = sc.nextInt();
            tab = new int[wierszy][kolumn];
            //for(int i = 0; i < wierszy*kolumn; i++)
            //{
            //  tab[(int)Math.floor((double)i/(double)kolumn)][i % kolumn] = sc.nextInt();
            //}
            for(int i = 0; i < tab.length; i++)
                for(int j = 0; j < tab[i].length; j++)
                    tab[i][j] = sc.nextInt();
                                                                } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void wyswietl()
    {
        for(int i = 0; i < tab.length; i++)
        {
            for(int j = 0; j < tab[i].length; j++)
            {
                System.out.printf("%d ", tab[i][j]);
            }
            System.out.printf("%n");
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
macierz t= new macierz();
t.wczytaj();
t.wyswietl();
    }
 
}

Comments