1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
stellarik [79]
3 years ago
9

4.2: Roman Numeral Converter Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch

statement to display the Roman numeral version of that number. Input Validation: Do not accept a number less than 1 or greater than 10. SAMPLE RUN #1: ./Test
Computers and Technology
1 answer:
Reptile [31]3 years ago
4 0

Answer:

The solution code is written in Java

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main (String [] args) {
  4.        Scanner inStream = new Scanner(System.in);
  5.        System.out.print("Please input a number (1 - 10): ");
  6.        int num = inStream.nextInt();
  7.        if(num < 1 || num > 10){
  8.            System.out.println("The input must be between 1 - 10");
  9.        }else{
  10.            switch(num){
  11.                case 1:
  12.                    System.out.println("I");
  13.                    break;
  14.                case 2:
  15.                    System.out.println("II");
  16.                    break;
  17.                case 3:
  18.                    System.out.println("III");
  19.                    break;
  20.                case 4:
  21.                    System.out.println("IV");
  22.                    break;
  23.                case 5:
  24.                    System.out.println("V");
  25.                    break;
  26.                case 6:
  27.                    System.out.println("VI");
  28.                    break;
  29.                case 7:
  30.                    System.out.println("VII");
  31.                    break;
  32.                case 8:
  33.                    System.out.println("VIII");
  34.                    break;
  35.                case 9:
  36.                    System.out.println("IX");
  37.                    break;
  38.                case 10:
  39.                    System.out.println("X");
  40.                    break;
  41.            }
  42.        }
  43.    }
  44. }

Explanation:

The first part of this program (Line 6 - 8) is to get input number from user using Scanner object. Input validation has been done to check if the input number is in the acceptable range (Line 10). If not, an error message will be displayed (Line 11).

If the input number is in the range of 1 - 10, the number will go through a series of switch statements checking. If the number meet the condition in one of the switch cases, it will print the corresponding roman numeral specified in the case block (Line 13 - 44). For example, if input number is 9, the case 9 condition is met and "IX" will be printed.

You might be interested in
What is a common indicator of a phishing attempt cyber awareness 2022
vivado [14]

There are several types of malicious document. A common indicator of a phishing attempt cyber awareness 2022 is that It includes a threat of dire circumstances.

  • Phishing attacks often makes use of email or malicious websites to infect the machine with malware and viruses so as to collect personal and financial information.

Cybercriminals often uses different means to lure users to click on a link or open an attachment that infects their computers thereby producing vulnerabilities for criminals to use to attack.

Learn more from

brainly.com/question/24069038

7 0
2 years ago
According to the video, what is used to create computer programs?
Lena [83]
Its a or b. znskdbxkdb
8 0
3 years ago
Read 2 more answers
Is it possible to do Agile project in Waterfall methodology?
MariettaO [177]
Yes, it could be possilbe
5 0
3 years ago
Read 2 more answers
PLEASE SOMEONE ANSWER THIS
maw [93]
Maybe 7411 or someones birthday in the family
3 0
2 years ago
Read 2 more answers
What is software piracy
Tju [1.3M]
Software piracy is the illegal copying, distribution, or use of software.
8 0
3 years ago
Read 2 more answers
Other questions:
  • What is a constructor? Why would you include a constructor in a class?
    6·1 answer
  • A section-lined area is always completely bounded or outlined by an?
    11·1 answer
  • In this exercise, use the following variables : i,lo, hi, and result. Assume that lo and hi each are associated with an int and
    9·1 answer
  • Mary is entering her senior year of college. She has a meeting on Friday with her advisor to discuss her career plans.Mary is al
    15·1 answer
  • Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
    8·1 answer
  • The move toward access instead of ownership is a sign of collaborative consumption.
    5·1 answer
  • According to the textbook, the definition of transition is
    13·1 answer
  • The metric unit used for length
    5·1 answer
  • Which Backstage view feature helps you to specifically remove customized information from a document? Protect Document Feedback
    14·1 answer
  • True or false: Quality score is an algorithm that scores each of your search ads on spelling and grammar.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!