Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ff877d

Browse files
Decision Structures
1 parent 63f04eb commit 4ff877d

File tree

3 files changed

+164
-57
lines changed

3 files changed

+164
-57
lines changed

‎Programming-Challenges/Decision-Structures/.idea/workspace.xml‎

Lines changed: 102 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Write a program that prompts the user to enter a number within the range of 1 through 10.
3+
The program should display the Roman numeral version of that number.
4+
If the number is outside the range of 1 through 10, the program should display an error message.
5+
*/
6+
7+
package com.challenges;
8+
9+
import java.util.Scanner;
10+
11+
public class RomanNumerals {
12+
public static void main(String [] args) {
13+
14+
// Declare Variables
15+
int userInput;
16+
17+
// Create a scanner object
18+
Scanner scanner = new Scanner(System.in);
19+
20+
//Prompt user for input
21+
System.out.println("Please enter a number from 1 to 10: ");
22+
userInput = scanner.nextInt();
23+
24+
// Check for range
25+
if(userInput < 1 || userInput > 10) {
26+
System.out.println("ERROR! Number out of range.");
27+
}
28+
else {
29+
System.out.print(userInput + " in Roman Numeral is, ");
30+
if(userInput == 1) {
31+
System.out.println("I");
32+
}
33+
else if(userInput == 2) {
34+
System.out.println("II");
35+
}
36+
else if(userInput == 3) {
37+
System.out.println("III");
38+
}
39+
else if(userInput == 4) {
40+
System.out.println("IV");
41+
}
42+
else if(userInput == 5) {
43+
System.out.println("V");
44+
}
45+
else if(userInput == 6) {
46+
System.out.println("VI");
47+
}
48+
else if(userInput == 7) {
49+
System.out.println("VII");
50+
}
51+
else if(userInput == 8) {
52+
System.out.println("VIII");
53+
}
54+
else if(userInput == 9) {
55+
System.out.println("IX");
56+
}
57+
else {
58+
System.out.println("X");
59+
}
60+
}
61+
}
62+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /