Untitled
TEXT
views 23
,
size 2204 b
``````package com.company;
import java.util.Random;

public class Macierz {
Random r = new Random();
private int n;

int tab[][] = new int[10][10];

public int nwd(int a, int b) {
if (a == b) return b;
else if (a == b) return a;
else if (b == 0) return a;
else {
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
return a;
}
}

public void wypełnijMacierz(int n) {

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a = i;
int b = j;
tab[i][j] = nwd(27,3);
}
}
}

public void wypisz(int n) {
for (int i = 0; i < n; i++) {
System.out.println();
for (int j = 0; j < n; j++) {
System.out.print(" " + tab[i][j] + " ");
}
}
}

public void wypelnij2(int n , int a) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
tab[i][j] = r.nextInt(a) + 1;
}
}

}

public void wypisz2(int n) {
for (int i = 0; i < n; i++) {
System.out.println();
for (int j = 0; j < n; j++) {
System.out.print(" " + tab[i][j] + " ");
}
}

}

public void sumaprzekatnej(int n) {
int suma = 0;
for (int i = 0; i < n; i++) {
suma = suma + tab[i][i];
}
System.out.println("Suma przekatnej wynosi : " + suma);
}

public void maxwiersz(int n) {
int sumaR;
int przechowaj = 0;
for (int i = 0; i < n; i++) {
sumaR = 0;
for (int j = 0; j < n; j++) {
sumaR = sumaR + tab[i][j];
if(sumaR > przechowaj)
przechowaj = sumaR;
}
System.out.println("Suma " + (i + 1) + " wiersza: " + sumaR);

}
System.out.println("Maksymalna suma wiersza to " + " " + przechowaj);
}
}``````