Prime #### Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime #### Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

# Checking if a number is positive or negative using Java ## A number is positive or negative using java :

In this article, we will create a java program to check whether the number entered by the user is positive or negative. The number is demonstrated as positive or negative by comparing the entered number with the Zero(0). If the number entered by the user is greater than zero, then the number is positive, else if the number is less than zero, then the number is negative and else the number is zero.

• N > 0 then, number is Positive.
• N < 0 then, number is Negative.
• N = 0 then, number is Zero.

## Algorithm

Step 1. Start

Step 2. Insert the number.

Step 3. If the number is Zero then print “The number is Zero”

Step4: If the number is greater than zero, then print, “The number is Positive”

Step 5. Else print, “The number is Negative”

Step 6. Stop

### Code in Java :

`import java.util.Scanner;public class Main{	public static void main(String[] args)	{		Scanner sc = new Scanner(System.in);		System.out.print("Enter a Number: ");		int n = sc.nextInt();     	        if (n==0)                     System.out.println("The number is Zero");                else if(n>0)                     System.out.println("The number is Positive");                else                     System.out.println("The number is Negative");		sc.close();	}}`

### Output :

```Enter a number: 96
The number is Positive``` 