Find whether a number is positive, negative or zero | Java Programs

Output:

*** Positive Or Negative Or Zero ***

Enter any number: 
-4
The number is negative.
------------------------------------
*** Positive Or Negative Or Zero ***

Enter any number: 
18
The number is positive.
------------------------------------
*** Positive Or Negative Or Zero ***

Enter any number: 
0
The number is zero.

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class PositiveOrNegativeOrZero {

    public static void main(String[] args) {
        Scanner obj = new Scanner(System.in);
        System.out.println("*** Positive Or Negative Or Zero ***" + "\n");
        System.out.println("Enter any number: ");
        int num = obj.nextInt();

        if (num > 0) {
            System.out.println("The number is positive.");
        } else if (num < 0) {
            System.out.println("The number is negative.");
        } else if (num == 0) {
            System.out.println("The number is zero.");
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon