Java program to check whether a number is positive, negative or zero













Java program to check whether a number is positive, negative or zero

Java Tutorial Java Exercises Data Structures











Java program to check whether a number is positive, negative or zero


/** * Java program to check whether a number is positive, negative or zero */ import java.util.Scanner; class Test { public static void main(String[] args) { int n; Scanner p=new Scanner(System.in); System.out.print("Enter any number"); n=p.nextInt(); if(n>0) { System.out.println(n+" Is Positive number"); } else if(n<0) { System.out.println(n+" Is negative number"); } else { System.out.println(n+" Is Zero"); } } }




Output:

Enter any number : 20 20 Is Positive number Enter any number : -20 -20 Is negative number Enter any number : 0 0 Is Zero