Reputation: 642
Simply, I have a set of numbers like this.
int targetNumber = 8;
int[] n = new int[4];
n[0] = 2;
n[1] = 4;
n[2] = 8;
n[3] = 16;
Now, I'm trying to return 3 numbers.
For example, since n[2]
is equal to the targetNumber
, I want to return n[0]
, n[1]
, and n[3]
.
Any ways on how I can do that?
Upvotes: 4
Views: 1548
Reputation: 33437
You can do it in classic fashion:
for (int i : n) {
if (i != targetNumber)
System.out.println(i);
}
output will be n[0]
, n[1]
and n[3]
2
4
16
Upvotes: 2