Enter any integer number as an input. Now we check whether the given number is greater than zero or not. If the given number is greater than zero than it is positve. If it is less than zero than it is negative and if it is zero than it is neither poistive nor negative.
Here is the source code of the Java Program to Check if a Given Integer is Positive or Negative. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Postive_Negative
public static void main(String args)
Scanner s = new Scanner(System.in);
System.out.print("Enter the number you want to check:");
n = s.nextInt();
if(n > 0)
System.out.println("The given number "+n+" is Positive");
else if(n < 0)
System.out.println("The given number "+n+" is Negative");
System.out.println("The given number "+n+" is neither Positive nor Negative ");
$ javac Postive_Negative.java $ java Postive_Negative Enter the number you want to check:6 The given number 6 is Positive
Sanfoundry Global Education & Learning Series - 1000 Java Programs.