Back

Getting An Exception Error

Created 1 year ago
47 Views
1 Comments
Sai_07
@Sai_07
Sai_07
@Sai_07Profile is locked. Login

Write a code to get the input in the given format and print the output in the given format

Input Description:
To take an integer value

Output Description:
Print the integer value

Sample Input :
2
Sample Output :
2
This the Java Solution:

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        System.out.println(n);
        
        sc.close();
    }
}

It is Working Normally in the Online Compiler.
But in the CodeKata I am getting:
Exception in thread "main" java.util.NoSuchElementException
	at java.base/java.util.Scanner.throwFor(Scanner.java:937)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
	at Main.main(Main.java:6)


Runtime Error (NZEC)
Can Anyone Provide the Solution
Comments
Please login to comment.