3. Write a Java program to check whether a number is negative, positive or zero.
Solution :-
Static
class posnegzero
{
public static void main(String args[])
{
int no1=-0;
if(no1 >0)
{
System.out.println("The number is Positive:- "+no1);
}
else if(no1 < 0)
{
System.out.println("The number is Negative :- "+no1);
}
else
{
System.out.println("The number is Zero :- "+no1);
}
}
}
Output :-
Dynamic
Solution
import java.util.*;
class posnegzero
{
public static void main(String args[])
{
int no1;
Scanner out = new Scanner(System.in);
System.out.println("Enter the first number :- ");
no1 = out.nextInt();
if(no1 > 0)
{
System.out.println("The number is Positive :- "+no1);
}
else if(no1 < 0)
{
System.out.println("The number is Negative :- "+no1);
}
else
{
System.out.println("The number is Zero :- "+no1);
}
}
}
Output :-