Java Program to Print the number is either positive negative or zero.
Java Program to Print the number is either positive negative or zero.
In this java program, we will read integer number and check whether it is positive, negative or zero.
Using If-else statement with Method
import java.util.Scanner;
class Number
{
String pnz(int a)
{
if(a<0)
return "Negative";
else if(a>0)
return "Positive";
return "Zero";
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number.");
int x=sc.nextInt();
Number n=new Number();
System.out.println(n.pnz(x));
}
}
Comments
Post a Comment
Please do not write any spam link in the comment box.