-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumToWord.java
More file actions
53 lines (44 loc) · 1.35 KB
/
NumToWord.java
File metadata and controls
53 lines (44 loc) · 1.35 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
import java.util.*;
// /*Write a java program which inputs a one digit number from the user (i.e. 0-9). The program should then print that number in words, e.g. “Zero” for 0, “One” for 1, “Two” for 2, and so on. If the user does not enter a one-digit number, then program should display an error: “Invalid number!”. */
public class NumToWord {
public static void main(String[] args) {
//create scanner to obtain input from command window
int num;
Scanner in = new Scanner(System.in);
System.out.println("Please enter a 1 digit number to return the english word for same: "); //prompt
num = in.nextInt(); //read number from user
switch (num) {
case 0:
System.out.println("Zero");
break;
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;
case 3:
System.out.println("Three");
break;
case 4:
System.out.println("Four");
break;
case 5:
System.out.println("Five");
break;
case 6:
System.out.println("Six");
break;
case 7:
System.out.println("Seven");
break;
case 8:
System.out.println("Eight");
break;
case 9:
System.out.println("Nine");
break;
}
in.close();
}
}