Check Number Sign
This program checks if a number is positive, negative, or zero.
Problem Statement
Write a Java program that checks if a number is positive, negative, or zero.
Source Code
| 1 | public class NumberSign { |
| 2 | public static void main(String[] args) { |
| 3 | int num = 0; |
| 4 | if(num > 0) { |
| 5 | System.out.println(num + " is positive - Eduinq"); |
| 6 | } else if(num < 0) { |
| 7 | System.out.println(num + " is negative - Eduinq"); |
| 8 | } else { |
| 9 | System.out.println(num + " is zero - Eduinq"); |
| 10 | } |
| 11 | } |
| 12 | } |
Program Output
0 is zero - Eduinq
Explanation
The program uses an if-else ladder to check three possibilities. - If the number is greater than zero, it prints positive. - If less than zero, it prints negative. - Otherwise, it prints zero. - This structure ensures only one condition executes, making it efficient for mutually exclusive checks. Conclusion: Shows classification of numbers using if-else ladder.