To check that a given number is positive, negative or
zero.
Answers
Explanation:
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 ");
}
}
}
Sample Output:
$ javac Postive_Negative.java
$ java Postive_Negative
Enter the number you want to check:6
The given number 6 is Positive
Explanation:
If there is a minus sign before that number it is negative number
Ex: -6
If there is a plus or no sign before that number it means it is positive number
Ex : +9 , 9
0=0