Check Negative Number
This program checks if a number is negative using an if statement.
Problem Statement
Write a Java program that checks if a number is negative.
Source Code
| 1 | public class NegativeCheck { |
| 2 | public static void main(String[] args) { |
| 3 | int num = -5; |
| 4 | if(num < 0) { |
| 5 | System.out.println(num + " is negative - Eduinq"); |
| 6 | } |
| 7 | } |
| 8 | } |
Program Output
-5 is negative - Eduinq
Explanation
int num = -5; Declares integer variable. - if(num < 0) Condition checks if num is less than 0. - Prints message if condition is true. Conclusion: Shows how to check negative numbers using if.