Dear Friends,
If I enter the wrong input(example , if I enter String instead of Integer) loop is not ending, it wont get input next time. can you please help this?. Thanks in advance!!!
import java.util.InputMismatchException; import java.util.Scanner; /** * If we enter the wrong input(example , if we enter sting instead of integer) it goes unending loop * * @author Nithish * */ public class Sample2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); for (int i = 0; i < 1; i++) { try { System.out.println("Enter the value"); int obj = scanner.nextInt(); System.out.println(obj); } catch (InputMismatchException e) { i--; e.printStackTrace(); } } } }