3x3 array find largest number
im making a 3x3 array filled with random numbers and im supposed to find the largest number in the array , i compiled my code and its working fine but i dont think im getting the right answer here's my code , any help will be greatly appreciated
Code Java:
public class matriz_mayor{
public static void main(String args[]){
int may, r, c;
int [][] v;
v = new int [3][3];
for(r=0;r<=2;r++){
for(c=0;c<=2;c++){
v [r][c] = new Double(Math.random() *10).intValue();
System.out.println("["+v[r]+"]" + "["+v[c]+"]");
}
may = v[0][0];
for(r=0;r<=2;r++){
for(c=0;c<=2;c++){
if(v[r][c]>may){
may = v[r][c];
}
}System.out.println("El numero mayor es" + may);
}
}
}
}run:
[[I@190d11][[I@190d11]
[[I@190d11][[I@a90653]
[[I@190d11][[I@de6ced]
El numero mayor es7
El numero mayor es7
El numero mayor es7
BUILD SUCCESSFUL (total time: 0 seconds)
Re: 3x3 array find largest number
You're are seeing the toString() result from an array of int. If you want to see what v[r] holds consider using Arrays.toString(v[r]):
Code java:
// at the top:
import java.util.Arrays;
// in your for loop:
System.out.println("[" + Arrays.toString(v[r]) + "]" + "[" + Arrays.toString(v[c]) + "]");