Q:

Java program to check number is positive, negative or zero

belongs to collection: Java Basic Programs

0

Java program to check number is positive, negative or zero

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to find largest number among three nu... >>
<< Java program to swap two numbers using function...