Answer to Question #310635 in Java | JSP | JSF for Jojo

Question #310635

Write a program that prompts the user to input an integer



between 0 to 35. It the number is less than or equal to 9, the



program should output the number; otherwise, it should output



A for 10, B for 11, C for 12, …, and Z for 35. (hint: use the cast



operator, (char)(), for numbers >+ 10.

1
Expert's answer
2022-03-13T01:11:48-0500
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int n = -1;

    while (n < 0 || n > 35) {
        System.out.println("Input n. n should be >= 0 and <= 35");
        n = scanner.nextInt();
    }

    if (n >= 0 && n <= 9) {
        System.out.println(n);
    } else {
        System.out.println((char) (55 + n));
    }
}

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