import java.util.*;
public class Receipt {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
int quantity;
try {
quantity = Integer.parseInt(userInput.nextLine());
} catch (NumberFormatException nfe) {
System.out.print("You gave me a wrong number sweetie... Do it again:");
quantity = userInput.nextInt();
}
}
}
}
Przejrzałem już kilka stron, które omawiają dany problem, ale jakoś dalej nie mogę zaimplementować rozwiązania w swoim programie. Może mi ktoś pomoc i wytłumaczyć jak użyć pętli while w bloku try catch tak, żeby to działało na zasadzie pobieraj liczbę i sprawdzaj do momentu aż użytkownik poda poprawnego inta?