check if a number is positive or negative using if else

Solutions on MaxInterview for check if a number is positive or negative using if else by the best coders in the world

showing results for - "check if a number is positive or negative using if else"
Avia
03 Jan 2017
1public class PositiveNegative {
2
3    public static void main(String[] args) {
4
5        double number = 12.3;
6
7        // true if number is less than 0
8        if (number < 0.0)
9            System.out.println(number + " is a negative number.");
10
11        // true if number is greater than 0
12        else if ( number > 0.0)
13            System.out.println(number + " is a positive number.");
14
15        // if both test expression is evaluated to false
16        else
17            System.out.println(number + " is 0.");
18    }
19}