ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.