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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad