import java.util.Scanner;
public class PositiveNegativeChecker {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
double number = input.nextDouble();
if (number > 0) {
System.out.println(number + " is positive.");
} else if (number < 0) {
System.out.println(number + " is negative.");
} else {
System.out.println("The number is zero.");
}
}
}
Enter a number: 12.9
12.9 is positive.
Enter a number: -14.3
-14.3 is negative.
Scanner
class. Then, we use an if
statement to check whether the number is greater than 0
. If it is, we print a message indicating that the number is positive. less than 0
, we print a message indicating that the number is negative. equal to 0
, we print a message indicating that the number is zero.System.out.println()
to print the appropriate message to the console.