C Write a program that prompts the user to input an integer between 0 and 35. The prompt should say Enter an integer between 0 and 35:. If 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: For numbers >

Respuesta :

ijeggs

Answer:

import java.util.Scanner;

public class num3 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter a number between 0 and 35: ");

       int num = in.nextInt();

       if (num <= 9) {

           System.out.println(num);

       } else {

           switch (num) {

               case 10:

                   System.out.println("A");

                   break;

               case 11:

                   System.out.println("B");

                   break;

               case 12:

                   System.out.println("C");

                   break;

               case 13:

                   System.out.println("D");

                   break;

               case 14:

                   System.out.println("E");

                   break;

               case 15:

                   System.out.println("F");

                   break;

               case 16:

                   System.out.println("G");

                   break;

               case 17:

                   System.out.println("H");

                   break;

               case 18:

                   System.out.println("I");

                   break;

               case 19:

                   System.out.println("J");

                   break;

               case 20:

                   System.out.println("K");

                   break;

               case 21:

                   System.out.println("L");

                   break;

               case 22:

                   System.out.println("M");

                   break;

               case 23:

                   System.out.println("N");

                   break;

               case 24:

                   System.out.println("O");

                   break;

               case 25:

                   System.out.println("P");

                   break;

               case 26:

                   System.out.println("Q");

                   break;

               case 27:

                   System.out.println("R");

                   break;

               case 28:

                   System.out.println("S");

                   break;

               case 29:

                   System.out.println("T");

                   break;

               case 30:

                   System.out.println("U");

                   break;

               case 31:

                   System.out.println("V");

                   break;

               case 32:

                   System.out.println("W");

                   break;

               case 33:

                   System.out.println("X");

                   break;

               case 34:

                   System.out.println("Y");

                   break;

               case 35:

                   System.out.println("Z");

                   break;

           }

       }

   }

}

Explanation:

  1. Using Java Language User is prompted to enter a number between 0-35
  2. This is stored in a variable num
  3. Used an if statement to check if num is between 0-9 (i.e less than 9) since user entered value strictly between 0-35
  4. Then in the else block Used a switch statement to assign the letters A-Z to num 10 - 35