5
I have an activity to do in which the teacher asks that the names of the numbers in the integers be converted (long int).
I wonder if in Java there is any function that does this... I searched in some places, but I did not find anything that could help me until then.
The code I made is just printing the number as a character without this conversion that the problem speaks of.
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();
}
Show what you have done so far by clicking EDIT and adding the question.
– user28595
Possible duplicate of How to share a
string
and then convert to int?– user28595
There is nothing ready in Java (it may be that someone created something outside). The problem here is the definition of the problem. Without knowing exactly what the problem is, there is no way to find the right solution. What do you really want to do? Create a function that takes a number in full and returns the same number (
long
)? Whether to returnlong
then you can’t go from 1 to 10. If so, the algorithm is absurdly more complex than what you’re doing, and you can’t start helping yourself. If you want to know how to return the number instead of printing, then it’s easy, but I doubt that this alone will solve.– Maniero
"Implement a class that takes the first ten numbers in full (from "one" to "ten") and converts them into integers (long int). Use conditional switch for conversion" This is the proposed problem
– Pokiha