Programming Examples
Java program to check whether a int type number taken as input is a positive, negative or a zero
Write a program to check whether a int type number taken as input is a positive, negative or a zero.
Solution
import java.util.*;
class CheckNumber
{
public static void main(String arr[])
{
int n;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number:”);
n=sc.nextInt();
if(n>0)
System.out.println(“Positive”);
else if(n<0)
System.out.println(“Negative”);
else
System.out.println(“Zero”);
}
}
Output