import java.util.Scanner;
public class hil {
public static void main(String[] args){
Scanner m = new Scanner(System.in);
System.out.print("Insert a number:");
int num = m.nextInt();
int[] ar = { 10, 20, 30, 40, 50 };
int sum = 0;
for (int i = 0; i < ar.length; i++) {
sum += i;
for (int n : ar) {
if (num == n) {
System.out.print(true);
} else {
System.out.print(false);
}
}
}
}
}
This my code I do get the right output but it shows true and false for all the values in the array . Not only the single value. How to get the true and false boolean value for the value entered not the rest of the value .
current output:
Insert a number:20
falsetruefalsefalsefalsefalsetruefalsefalsefalsefalsetruefalsefalsefalsefalsetruefalsefalsefalsefalsetruefalsefalsefalse
desired output:
Insert a number:20
true