Q:

Java program to check number is positive, negative or zero

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now