Escolar Documentos
Profissional Documentos
Cultura Documentos
Scanner;
while (true) {
try {
System.out.print("Digite o primeiro valor: ");
valor1 = Float.parseFloat(scanner.nextLine());
break;
} catch (NumberFormatException e) {
System.out.println("Erro: é necessário digitar um número. Tente novamente.");
}
}
while (true) {
try {
System.out.print("Digite o segundo valor: ");
valor2 = Float.parseFloat(scanner.nextLine());
break;
} catch (NumberFormatException e) {
System.out.println("Erro: é necessário digitar um número. Tente novamente.");
}
}
scanner.close();
}
}