Java Code: Write a Java program to Check Whether a Number is Positive or Negative or Zero
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public static void main(String[] args) { // input from standard input - keyboard Scanner reader = new Scanner(System.in); System.out.print("Enter a number: "); // nextDouble() reads the next integer from the keyboard double number = reader.nextDouble(); // true if number is less than 0 if (number < 0.0) System.out.println(number + " is a negative number."); // true if number is greater than 0 else if ( number > 0.0) System.out.println(number + " is a positive number."); // if both test expression is evaluated to false else System.out.println(number + " is 0."); } |
Output:
In this example you have learned how to Check Whether a Number is Positive or Negative or Zero