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).
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).
A direct, practical approach (building on 's suggestion): iterate the 2D array with index-aware loops, test each element against the threshold, and print or collect the matching coordinates. The key clarifications often missing in short answers are the coordinate convention (row-first vs column-first), zero-based indexing in Java, and handling ragged rows.
int threshold = 4;
int[][] a = /* existing data */;
for (int row = 0; row < a.length; row++) {
for (int col = 0; col < a[row].length; col++) {
if (a[row][col] > threshold) {
// Common convention: (row, col)
System.out.println("Found at (row=" + row + ", col=" + col + "): " + a[row][col]);
// If the posting expects (x,y) where x=column, y=row, print (col, row) instead.
}
}
} Notes and pitfalls:
a[row].length because rows can be ragged (different lengths).for loops hide indices; classic for or IntStream.range is clearer when indexes are needed.If the thread was cross-posted (as observed), consolidation prevents duplicated effort. For general reference on Java arrays and indexing, see the Java tutorial on arrays: Java arrays tutorial.
Jump to Post— Phaelax 52didn't you post this on javaboutique as well? i posted an answer on there.
You could construct two for loops which search through the array - one inside the other. Then when you find which value you are looking at - just print out the number each bit of the for loop got to.
didn't you post this on javaboutique as well? i posted an answer on there.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.