You’d better simplify all of this, you don’t need to call your method multiple times :
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (writeAndCheckEven(Integer.parseInt(scanner.nextLine()))) {
System.out.println("You added an even number, go on");
}
System.out.println("You added an odd number, done!");
}
private static boolean writeAndCheckEven(int number) {
return number % 2 == 0;
}
- you don’t need to use a
returnif there is no more code after - you can directly use the
scannerin the parameter - don’t use both
whileandifit won’t do what you want
solved Trying to test if an input is odd or even