Java Program to Check for the Negative Number

The program shows how to Check for the Negative Number in java. This program is also a good demonstration to know the working process of the if-else statement.

If you do not understand the program, perhaps you may want to learn about the if-else statement first.


Java Program to Check for the Negative Number

 //check for the negative number using if-else statement in java

 public class IfElseNegNumber
 {
   public static void main(String[] args) 
   {
     int num = 5;
      
      if(num < 0)  //checking condition for true
      { 
        System.out.println("Number is negative");
      }
      else //executed if the condition is false
      { 
        System.out.println("Number is positive");
      }
        
      System.out.println("Always executed");
   }
   
 }

Output:

Number is positive
Always executed