Answer the question
In order to leave comments, you need to log in
Finding a number in an array. How to display only one answer?
Finding a number in an array:
public class Main {
interface GetNum {
void num(int[] x);
}
public static void main(String[] args) {
int[] arr = {15, 16, 18, 19, 22, 0, -2, -4, 44};
GetNum getNum = (x) -> {
for (int j : arr) {
if (j != -4) {
continue;
} else {
System.out.println("Есть!");
break;
}
}
System.out.println("Нету!");
};
getNum.num(arr);
}
}
Answer the question
In order to leave comments, you need to log in
When exiting the loop, it will always write what is not found, you still need to use the flag.
For example so.
boolean f = false;
for (int j : arr) {
if (j == x) {
f = true;
break;
}
}
if (!f)
{System.out.println("No!");}
else
{System.out.println("Yes!");}
This is invalid json. Accordingly, this is not json at all. Or turn it into json or write a parser for this miracle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question