radko93

tabliczka2

Jan 20th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public class tabliczka2 {
  2.  
  3.     int j = 5;
  4.     int i = 5;
  5.     int tab[][];
  6.  
  7.     public tabliczka2(int i, int j) {
  8.         this.j = j;
  9.         this.i = i;
  10.         tab = new int[i][j];
  11.     }
  12.  
  13.     public void wypelnij(int a, int b, int wielX, int wielY) {
  14.         for (int x = 0; x <= wielX; x++) {
  15.             for (int y = 0; y <= wielY; y++) {
  16.                 tab[x][y] = (int) (Math.random() * (b - a) + a);
  17.             }
  18.         }
  19.     }
  20.  
  21.     public void usunNaj() {
  22.         int naj = 0, xNaj = -1, yNaj = -1;
  23.  
  24.         for (int x = 0; x < tab.length; x++) {
  25.             for (int y = 0; y < tab[x].length; y++) {
  26.                 if (tab[x][y] >= naj) {
  27.                     naj = tab[x][y];
  28.                     xNaj = x;
  29.                     yNaj = y;
  30.                 }
  31.             }
  32.         }
  33.         for (int x2 = 0; x2 < tab.length; x2++) {
  34.             tab[x2][yNaj] = 0;
  35.            
  36.         }
  37.         for (int y2 = 0; y2 < tab[xNaj].length; y2++) {
  38.             tab[xNaj][y2] = 0;
  39.         }
  40.        
  41.         System.out.println("Najwiekszy element to: " + naj);
  42.  
  43.     }
  44.  
  45.     public void wyswietl() {
  46.         for (int x = 0; x < tab.length; x++) {
  47.             System.out.print(x + " | \t");
  48.             for (int y = 0; y < tab[x].length; y++) {
  49.                 System.out.print(tab[x][y] + "\t");
  50.             }
  51.             System.out.println();
  52.         }
  53.     }
  54.  
  55.     public static void main(String[] args) {
  56.         tabliczka2 test = new tabliczka2(4, 4);
  57.         test.wypelnij(10, 50, 2, 2);
  58.         test.wyswietl();
  59.         test.usunNaj();
  60.         test.wyswietl();
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment