Answers for "Check if a Number is Positive or Negative using if else"

0

Check if a Number is Positive or Negative using if else

public class PositiveNegative {

    public static void main(String[] args) {

        double number = 12.3;

        // 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.");
    }
}
Posted by: Guest on June-03-2021

Code answers related to "Check if a Number is Positive or Negative using if else"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language