-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberToWords.java
More file actions
57 lines (52 loc) · 1.81 KB
/
Copy pathNumberToWords.java
File metadata and controls
57 lines (52 loc) · 1.81 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
import javax.swing.JOptionPane;
public class NumberToWords {
public static void main(String[] args) {
String input = JOptionPane.showInputDialog("Enter a whole number from 0-10:");
try {
int number = Integer.parseInt(input);
if (number >= 0 && number <= 10) {
String words = "";
switch (number) {
case 0:
words = "Zero";
break;
case 1:
words = "One";
break;
case 2:
words = "Two";
break;
case 3:
words = "Three";
break;
case 4:
words = "Four";
break;
case 5:
words = "Five";
break;
case 6:
words = "Six";
break;
case 7:
words = "Seven";
break;
case 8:
words = "Eight";
break;
case 9:
words = "Nine";
break;
case 10:
words = "Ten";
break;
}
JOptionPane.showMessageDialog(null, "Number in words: " + words);
} else {
JOptionPane.showMessageDialog(null, "Error: Number not in range.");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error: Invalid input. Please enter a whole number.");
}
}
}