-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberPrompt.java
More file actions
77 lines (69 loc) · 2.19 KB
/
numberPrompt.java
File metadata and controls
77 lines (69 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Jason Guo
import java.util.Scanner;
public class numberPrompt{
public static void main (String[] args){
int numberInput=0;
String romanNumeral = "";
boolean getInputBoolean = false;
Scanner input = new Scanner(System.in);
while (!getInputBoolean){
try{
System.out.println("Please enter an integer between 1 and 10");
numberInput = input.nextInt();
if (numberInput >= 1 && numberInput <= 10){
getInputBoolean = true;
switch (numberInput){
case 1: romanNumeral = "I";
break;
case 2: romanNumeral = "II";
break;
case 3: romanNumeral = "III";
break;
case 4: romanNumeral = "IV";
break;
case 5: romanNumeral = "V";
break;
case 6: romanNumeral = "VI";
break;
case 7: romanNumeral = "VII";
break;
case 8: romanNumeral = "VIII";
break;
case 9: romanNumeral = "IX";
break;
case 10: romanNumeral = "X";
break;
}
}
else{
System.out.println("\nYou did not enter an integer in this range");
input.nextLine();
}
}
catch (Exception e){
System.err.println(e);
System.out.println("\nYou did not enter a valid integer input.");
input.nextLine();
}
}
input.close();
System.out.println("The number you inputted was: " + numberInput + ".");
System.out.println("The corresponding Roman Numeral is: " + romanNumeral + ".");
}
}
/*
* Welcome to DrJava. Working directory is F:\Current\Computer Science
> run numberPrompt
Please enter an integer between 1 and 10
[DrJava Input Box]
java.util.InputMismatchException
You did not enter a valid integer input.
Please enter an integer between 1 and 10
[DrJava Input Box]
java.util.InputMismatchException
You did not enter a valid integer input.
Please enter an integer between 1 and 10
[DrJava Input Box]
The number you inputted was: 5.
The corresponding Roman Numeral is: V.
> */