Java Intro Example

🧩 Syntax:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();

        if (!isNumeric(input)) {
            System.out.println("Error: not a number.");
            return;
        }
        int number = Integer.parseInt(input);
        if (number % 2 == 0) {
            System.out.println("The number is even.");
        } else {
            System.out.println("The number is odd.");
        }
    }

    static boolean isNumeric(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }
        for (char c : str.toCharArray()) {
            if (!Character.isDigit(c) && !(c == '-' && str.indexOf(c) == 0)) {
                return false;
            }
        }
        return true;
    }
}