2
In the code below I treated the error only that after treating it still appears the quantity name (I sent the photo below to facilitate understanding). How do I make him not show the quantity name? I would also like to know if in case an exception occurred the user had another chance to write the price again.
System.out.println("NOME DO PRODUTO: ");
produto.setNome(entrada.next().trim().replace(" ", "").toUpperCase());
try {
System.out.print("PREÇO: ");
produto.setPreco(entrada.nextDouble());
}catch(java.util.InputMismatchException e) {
System.out.print("ERRO");
}
System.out.print("QUANTIDADE: ");
item.setQuantidade(entrada.nextInt());
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero