0

import java.util.Scanner;

public class Test {

public static void main(String[] args) 
{
    try(Scanner sc = new Scanner(System.in))
    {
        System.out.println("Please enter");
        System.out.println(sc.nextLine());
    }
    try(Scanner sc1 = new Scanner(System.in))
    {
        System.out.println("Please enter");
        System.out.println(sc1.nextLine());
    }

}

}

When I run the above code it is giving the following error :

Please enter
jhj ghuh
jhj ghuh
Exception in thread "main" Please enter
java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Unknown Source)
    at Test.main(Test.java:16)

Can someone please help what is wrong in this case ?

0 Answers0