I have an activity to do in which the teacher asks that the names of the numbers be converted into integers ( long int ).
I would like to know if there is a function in Java that does this ... I searched in some places, but found nothing that could help me until then.
The code I've done is just printing the number as a character without this conversion that the problem talks about.
public static void converte(String entrada) {
switch (entrada) {
case "um":
System.out.println("1");
break;
case "dois":
System.out.println("2");
break;
case "três":
System.out.println("3");
break;
case "quatro":
System.out.println("4");
break;
case "cinco":
System.out.println("5");
break;
case "seis":
System.out.println("6");
break;
case "sete":
System.out.println("7");
break;
case "oito":
System.out.println("8");
break;
case "nove":
System.out.println("9");
break;
case "dez":
System.out.println("10");
break;
}
}
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;
}
converte(entrada);
}
System.out.println("Fim!");
key.close();
}