This is a Java Program to Check if a Given Integer is Positive or Negative.
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.
import java.util.Scanner;
public class Postive_Negative
{
public static void main(String[] args)
{
int n;
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");
}
else
{
System.out.println("The given number "+n+" is neither Positive nor Negative ");
}
}
}
Output:
$ 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.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Apply for Java Internship
- Check Programming Books
- Practice BCA MCQs
- Check Java Books
- Apply for Computer Science Internship