23. JAVA Program To Check A Number Is Positive Or Negative.
How does this program work?
- In this program you are going to learn about How to check a number is positive integer or negative integer by using java.
- Here we using if case to compare the given number with zero if the number is greater then zero then it print result as positive number else it show result as negative number.
- in this concept you will learn about how to use if case in java .
Here is the code
// To check a number positive or negative.
import java.util.Scanner;public class Number
{
public static void main(String args[] )
{
int a;
System.out.println("Enter the number\n" );
Scanner obj1=new Scanner(System.in );
a=obj1.nextInt();
if(a>0)
{
System.out.println("The given number is a positive number");
}
else
if(a<0)
{
System.out.println("The given number is a negative number");
}
}
}