<h2>
Answer:</h2>
//import the Scanner class to allow for user's input
import java.util.Scanner;
// Write the class header with the appropriate name
public class RomanNumerals {
// Write the main method - this is where execution begins
public static void main(String[] args) {
//Create an object of the Scanner class to allow user's to enter the number
Scanner input = new Scanner(System.in);
//Prompt the user to enter a number
System.out.println("Please enter a number within the range of 1 through 10");
//Receive the number from the user and store in an int variable
int num = input.nextInt();
//Begin the switch statement using the num
switch (num) {
//If the number is 1
//Print the corresponding Roman numeral -> I
//Then break out of the switch statement
case 1 :
System.out.println("I");
break;
//If the number is 2
//Print the corresponding Roman numeral -> II
//Then break out of the switch statement
case 2 :
System.out.println("II");
break;
//If the number is 3
//Print the corresponding Roman numeral -> III
//Then break out of the switch statement
case 3:
System.out.println("III");
break;
//If the number is 4
//Print the corresponding Roman numeral -> IV
//Then break out of the switch statement
case 4:
System.out.println("IV");
break;
//If the number is 5
//Print the corresponding Roman numeral -> V
//Then break out of the switch statement
case 5:
System.out.println("V");
break;
//If the number is 6
//Print the corresponding Roman numeral -> VI
//Then break out of the switch statement
case 6:
System.out.println("VI");
break;
//If the number is 7
//Print the corresponding Roman numeral -> VII
//Then break out of the switch statement
case 7:
System.out.println("VII");
break;
//If the number is 8
//Print the corresponding Roman numeral -> VIII
//Then break out of the switch statement
case 8:
System.out.println("VIII");
break;
//If the number is 9
//Print the corresponding Roman numeral -> IX
//Then break out of the switch statement
case 9:
System.out.println("IX");
break;
//If the number is 10
//Print the corresponding Roman numeral -> X
//Then break out of the switch statement
case 10:
System.out.println("X");
break;
//If the number is not within range [That is the default case]
//Print the corresponding error message.
//You might want to print the error message using
//System.err.println() rather than
//the regular System.out.println()
//Then break out of the switch statement
default:
System.err.println("Error: The number should not be less than 1 or greater than 10");
break;
} //End of switch statement
} // End of main method
} // End of class declaration
=============================================================
<h2><u>
Sample Output 1:</u></h2>
>> Please enter a number within the range of 1 through 10
5
>> V
<h2>
</h2>
==============================================================
<h2><u>
Sample Output 2:</u></h2>
>> Please enter a number within the range of 1 through 10
0
>> Error: The number should not be less than 1 or greater than 10
<h2 />
===============================================================
<h2>
</h2><h2>
</h2><h2>
</h2><h2>
</h2><h2>
Explanation:</h2>
The code has been written in Java and it contains comments explaining every section of the code, please go through the comments to get a better understanding of the code.
Actual codes are written in bold face to distinguish them from the comments.