Answer to Question #271739 in Java | JSP | JSF for jade

Question #271739

Using the ternary operator ( ? : ), write a Java program that prompts the user to input an integer and then checks if the number is positive or negative or equal to zero.



1
Expert's answer
2021-11-26T17:43:14-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int number = in.nextInt();
        System.out.println(number > 0 ? "Positive" : number < 0 ? "Negative" : "Zero");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS