### Java Program to Check if given Number is Positive or Negative - The Coding Shala

Home >> Java Programs >> Check if the given number is positive or negative

In this post, we will learn How to write a Java program to check if the given number is positive or negative.

## Java Program to Check if given Number is Positive or Negative

Write a Java program to check if the given number is positive or negative.

Example 1:
Input: 22
Output: 22 is a positive number

Approach:

If the given number is smaller than 0 then it's negative otherwise it is positive, using if condition we will check that.

Java Program:

```/**
* https://www.thecodingshala.com/
*/

import java.util.Scanner;

public class Main {

public static void checkNum(int num) {
if (num < 0) {
System.out.println(num + " is a negative number");
} else {
System.out.println(num + " is a positive number");
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
// considering integers only
int num = sc.nextInt();
checkNum(num);
}
}```

Output:

```Enter the number
22
22 is a positive number
```

Other Posts You May Like