Java program to check the given number is positive or negative
KW.java
import java.util.Scanner;
class KW 
{
    public static void main(String args[])
    {
        int n;
        Scanner sc=new Scanner(System.in);
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program to check the given number is +ve/-ve");
        System.out.println("———————————————————————————————————————————");
        System.out.print("Enter a number ");
        n=sc.nextInt();
        if(n < 0)
        {
            System.out.println("\nEntered number is negative");
        }
        else if(n > 0)
        {
            System.out.println("\nEntered number is positive");
        }
        else
        {
            System.out.println("\nEntered number is zero");
        }
        System.out.println("———————————————————————————————————————————");
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Program to check the given number is +ve/-ve ——————————————————————————————————————————— Enter a number 0 Entered number is zero ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement