Skip to content

Instantly share code, notes, and snippets.

@mdukat
Created November 7, 2021 11:49
Show Gist options
  • Save mdukat/13bd0b1fd21d09d81a692fd8250c8cad to your computer and use it in GitHub Desktop.
Save mdukat/13bd0b1fd21d09d81a692fd8250c8cad to your computer and use it in GitHub Desktop.
zadanie 8
// Zadanie 8
{
System.out.println("Zadanie 8\n");
byte[][] tab = new byte[5][5];
for(int i = 0; i<5; i++){
for(int j = 0; j<5; j++){
tab[i][j] = (byte)((Math.random() * (125-0)) + 0);
}
}
System.out.println("tablica");
for(int i = 0; i<5; i++){
for(int j = 0; j<5; j++){
System.out.print(tab[i][j] + "\t");
}
System.out.println();
}
System.out.println();
// 8.1
boolean lewaEqPrawa = true;
for(int j = 0; j<5; j++){
if(tab[0][j] != tab[4][j])
lewaEqPrawa = false;
}
System.out.println("Lewa == Prawa: " + lewaEqPrawa);
// 8.2
boolean goraEqDol = true;
for(int i = 0; i<5; i++){
if(tab[i][0] != tab[i][4])
goraEqDol = false;
}
System.out.println("Góra == Dół: " + goraEqDol);
// 8.3
/*
0 1 2 3 4
---------------------
0 | P G 0 0 0
1 | D P G 0 0
2 | 0 D P G 0
3 | 0 0 D P G
4 | 0 0 0 D P
[0][1] == [1][0]
[1][2] == [2][1]
[2][3] == [3][2]
[3][4] == [4][3]
*/
boolean nadEqPod = true;
boolean printValues = false;
for(int i = 0; i<5-1; i++){
if(tab[i][i+1] != tab[i+1][i]) {
nadEqPod = false;
if(printValues){ // sanity check
System.out.println("Nad: " + tab[i][i+1] + "; Pod: " + tab[i+1][i]);
}
}
}
System.out.println("Nad przekątną == Pod przekątną: " + nadEqPod);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment