Java Fundamentals Challenge: Build a Basic Number Analyzer
• Updated 3/8/2026 • javajava fundamentalsbeginner coding challengeconditionalsscanneruser inputmodulusconsole app
1. Problem statement
Create a Java program that asks the user to enter one whole number. The program should analyze the number and display whether it is positive, negative, or zero, and also whether it is even or odd.
This challenge is great for beginners because it focuses on core Java skills: reading input, using variables, and making decisions with if statements.
2. Input and output expectations
- Input: One integer entered by the user.
- Output: A clear message showing:
- the number entered
- whether it is positive, negative, or zero
- whether it is even or odd
If the user enters invalid input, the program should show a friendly error message.
3. Constraints
- Use Java only.
- Do not use file input or file output.
- Do not use databases or network requests.
- Handle invalid input safely.
- Keep the solution beginner-friendly and readable.
4. Hints
- Use Scanner to read input from the user.
- Use hasNextInt() before reading the number.
- Use if, else if, and else to check whether the number is positive, negative, or zero.
- Use the modulus operator % to check whether a number is even or odd.
5. Solution explanation
First, the program asks the user to enter a whole number. Before reading it, the program checks whether the input is actually an integer. If not, it prints an error message and stops.
After getting a valid integer, the program uses conditional statements to find its sign:
- greater than 0 means positive
- less than 0 means negative
- equal to 0 means zero
Then it checks whether the number is even or odd:
- if number % 2 == 0, the number is even
- otherwise, it is odd
Finally, the program prints the full analysis in a clean format.
6. Solution code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a whole number: ");
if (!scanner.hasNextInt()) {
System.out.println("Error: Please enter a valid whole number.");
scanner.close();
return;
}
int number = scanner.nextInt();
String sign;
if (number > 0) {
sign = "Positive";
} else if (number < 0) {
sign = "Negative";
} else {
sign = "Zero";
}
String parity;
if (number % 2 == 0) {
parity = "Even";
} else {
parity = "Odd";
}
System.out.println("Number: " + number);
System.out.println("Sign: " + sign);
System.out.println("Type: " + parity);
scanner.close();
}
}
/*
Sample Output:
Enter a whole number: -7
Number: -7
Sign: Negative
Type: Odd
*/
7. Variations or next challenges
- Ask the user for two numbers and print the larger one.
- Check whether a number is divisible by 3, 5, or both.
- Turn this into a small menu-based number checker.
- Accept multiple numbers and count how many are positive, negative, even, and odd.
8. Related snippets or guides
- Using Scanner for user input in Java
- Writing if / else if / else conditions
- Using the modulus operator % in Java
- Basic input validation for beginner console apps

