I participate in programming competitions a lot and the most important part of that is taking input from user for that we generally use two things
- BufferedReader
- Scanner
Now the problem is sometimes each of the above while taking input gives following errors 1. Nullpointer exception 2. NoSuchElementFoundException
Below is the code for both
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
Scanner is
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Can anyone explain why this is happening so?