How to print out the position of 2 dimension arrays?

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

Thread: How to print out the position of 2 dimension arrays?

1. Registered User
Join Date
Nov 2004
Posts
3

How to print out the position of 2 dimension arrays?

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).

2. Senior Member
Join Date
Mar 2004
Posts
635
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();
}```

3. Registered User
Join Date
Nov 2004
Posts
3

no

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.

4. Senior Member
Join Date
Feb 2004
Posts
541
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.

5. Registered User
Join Date
Nov 2004
Posts
3

thank you

But where to put if to print out the position if there are more than 2 values greater than 4?

6. Senior Member
Join Date
Feb 2004
Posts
541
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 + ")");
}```

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise
 Questions? Contact us. C++ Web Development Wireless Latest Tips Open Source