Java

Program to check whether the input number is positive or negative.

Program to check whether the input number is positive or negative.
import java.util.Scanner;
public class demo1
{
    public static void main(String[] args) 
    {
        int num;
        Scanner n = new Scanner(System.in);
        System.out.print("Enter the number:");
        num = n.nextInt();
        n.close();
        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(num+" is neither positive nor negative");
        }
    }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.