Programming Examples

Java program to check number is negative positive or zero


Write a Program input any Integer number and check number is Negative, Positive or Zero. use only if statement.

Solution

import java.util.Scanner;
public class OnlyIfStatement 
{
    public static void main(String args[]) 
	{
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int number = sc.nextInt();
        if (number > 0) {
            System.out.println("The number is positive.");
        }
        if (number < 0) {
            System.out.println("The number is negative.");
        }
        if (number == 0) {
            System.out.println("The number is zero.");
        }
    }
}
Output

Enter a number: 5

The number is positive.


----------------------------------

Enter a number: -3

The number is negative.


----------------------------------------


Enter a number: 0

The number is zero.

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