Why I am getting the error java.util.NoSuchElementException while running the code ?

/* package codechef; // don’t place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
	public static void main (String[] args) throws java.lang.Exception
		// your code goes here
		int i;
		Scanner sc = new Scanner(System.in);
		i = sc.nextInt();

the code sc.nextInt() tries to read next Integer value from the standard input but seems like there’s no integer input provided. Read more about Scanner methods and Standard Input Output.

1 Like