there are 2 dimension arrays, how can print out the position of value than 4?
for example
0 2 3 2 2 2
0 1 1 2 5 3
1 2 3 3 2 1
print out:
The pos is ( 4,1).
Printable View
there are 2 dimension arrays, how can print out the position of value than 4?
for example
0 2 3 2 2 2
0 1 1 2 5 3
1 2 3 3 2 1
print out:
The pos is ( 4,1).
You mean something like this?
Code:for (int y=0; y<3; y++)
{
for(int x=0; x<6; x++)
System.out.print(array[x][y]+" ");
System.out.println();
}
Sorry, I just want to print out the position that the value great than 4 in the array. e.g. 5 > 4, I want to print out the position of 5.
Well you can just alter Phaelax's example. Put an if statement in there so you can check if the number in the current location is greater than 4.
But where to put if to print out the position if there are more than 2 values greater than 4?
Phaelax's example loops through the entire array. If you replace his print statement with something like
Code:if(array[x][y]>4)
{
System.out.println("(" + y + "," + x + ")");
}