Java Program - 08: Positive or Negative number check by java program . Example with output

in #java7 years ago

Run Java1.jpg

Here, Two java program show where first java program check whether the specified number is positive or negative.

The second program takes the input number (entered by user) and checks whether it is positive or negative and displays the result.
→ If a number is greater than zero then it is a positive number
→ If a number is less than zero then it is a negative number
→ If a number is equal to zero then it is neither negative nor positive.
Lets write this logic in a Java Program.

Example -01: Program to check whether the given number is positive or negative.

In this program we have specified the value of number during declaration and the program checks whether the specified number is positive or negative. To understand this program you should have the basic knowledge of if-else-if statement in Core Java Programming.

pn1.PNG

Output :
109 is a positive number

Example -02: Check whether the input number( entered by user) is positive or negative.

Here we are using Scanner to read the number entered by user and then the program checks and displays the result.

pn2.PNG

Output :
Enter the number you want to check : -12
-12 is negative number

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 57527.13
ETH 2375.07
USDT 1.00
SBD 2.42