[Solved] Trying to test if an input is odd or even


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 return if there is no more code after
  • you can directly use the scanner in the parameter
  • don’t use both while and if it won’t do what you want

solved Trying to test if an input is odd or even