Check whether the input number(entered by user) is positive or negative

Check whether the input number(entered by the user) is positive or negative


PROGRAM:

import java.util.Scanner;
public class Demo
{
    public static void main(String[] args) 
    {
        int number;
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter the number you want to check:");
        number = scan.nextInt();
        scan.close();
        if(number > 0)
        {
            System.out.println(number+" is positive number");
        }
        else if(number < 0)
        {
            System.out.println(number+" is negative number");
        }
        else
        {
            System.out.println(number+" is neither positive nor negative");
        }
    }
}

OUTPUT:

Enter the number you want to check:-12
-12 is negative number

Post a Comment

0 Comments