I have a problem with my program. I want to print min and max in each column but It doesn't work properly. I think everything should be ok. When the loop comes to end I restart min and max value.
public class tablice2 {
public static void main(String[] args){
int t [][] = new int [5][5];
int n [] = new int [5];
int x [] = new int [5];
Random r = new Random();
int min = t[0][0];
int max = t[0][0];
for (int i = 0; i <t.length ;i++){
min = 0;
max = 0;
for(int j = 0; j < t[i].length ;j++){
t[i][j] = r.nextInt(6)-5;
System.out.print(t[i][j] + " ");
if (t[j][i] < min){
min = t[j][i];
}
if (t[j][i] > max){
max = t[j][i];
}
}
n[i]=min;
x[i]=max;
System.out.println(" ");
}
for(int p=0;p<x.length;p++){
System.out.println("Max Column "+p + ": " +x[p] );
}
for(int k=0;k<n.length;k++){
System.out.println("Min Column "+k + ": " +n[k]);
}
}
}
minto zero. it can only be assigned values smaller than that (negative?) but random produces positive values