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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad