Home »
Java Programs »
Java Basic Programs
Java program to check number is positive, negative or zero
Check positive, negative and zero in java: In this java program, we will read and integer number and check whether it is positive, negative or zero.
Check Number is Positive, Negative or Zero using Java Program
//Java program to check number is positive, negative or zero.
import java.util.*;
class PosNegZero
{
public static void main(String []s)
{
int num;
//Scanner class to read value
Scanner sc=new Scanner(System.in);
System.out.print("Enter any integer number: ");
num=sc.nextInt();
//check condition for +ve, -ve and Zero
if(num>0)
System.out.println(num + " is POSITIVE NUMBER.");
else if(num<0)
System.out.println(num + " is NEGATIVE NUMBER.");
else
System.out.println("IT's ZERO.");
}
}
Output
Complie : javac PosNegZero.java
Run : java PosNegZero
Output
Enter any integer number: 0
IT's ZERO.
Enter any integer number: 999
999 is POSITIVE NUMBER.
Enter any integer number: -09090
-9090 is NEGATIVE NUMBER.
Java Basic Programs »