forked from maniero/SOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordsToNumber.java
More file actions
48 lines (46 loc) · 1.15 KB
/
Copy pathWordsToNumber.java
File metadata and controls
48 lines (46 loc) · 1.15 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
import java.util.*;
class Main {
public static long converte(String entrada) {
switch (entrada) {
case "um":
return 1;
case "dois":
return 2;
case "três":
return 3;
case "quatro":
return 4;
case "cinco":
return 5;
case "seis":
return 6;
case "sete":
return 7;
case "oito":
return 8;
case "nove":
return 9;
case "dez":
return 10;
default:
return -1;
}
}
public static void main(String[] args) {
Scanner key = new Scanner(System.in);
System.out.println("Inicialização...\nInstruções:\n1-Digite o nome de um número entre um~dez.\n2-O programa encerra ao digitar 'fim'.");
while (true) {
String entrada = key.nextLine();
if (entrada.equals("fim")) break;
long convertido = converte(entrada);
if (convertido == -1) {
System.out.println("Palavra inválida");
continue;
}
System.out.println(convertido);
}
System.out.println("Fim!");
key.close();
}
}
//https://pt.stackoverflow.com/q/256361/101