Java Program to Check if a Number is Positive or Negative

bookmark

public class CheckPositiveOrNegativeExample1  
{  
public static void main(String[] args)   
{  
//number to be check  
int num=912;  
//checks the number is greater than 0 or not  
if(num>0)  
{  
System.out.println("The number is positive.");  
}  
//checks the number is less than 0 or not  
else if(num<0)  
{  
System.out.println("The number is negative.");  
}  
//executes when the above two conditions return false  
else  
{  
System.out.println("The number is zero.");  
}  
}  
}  

 

public class CheckPositiveOrNegativeExample1  
{  
public static void main(String[] args)   
{  
//number to be check  
int num=912;  
//checks the number is greater than 0 or not  
if(num>0)  
{  
System.out.println("The number is positive.");  
}  
//checks the number is less than 0 or not  
else if(num<0)  
{  
System.out.println("The number is negative.");  
}  
//executes when the above two conditions return false  
else  
{  
System.out.println("The number is zero.");  
}  
}  
}  


Output:

The number is positive.

The number is positive.