- 1

Why is hasNext() method in java returns true without even adding anything in stdin?

I was working on a program in java to known the EOF of the input file When doing this the following code is a bit confusing Scanner in=new Scanner(System.in); System.out.println(in.hasNext()); This code outputs "true" even without taking any input?

1st Dec 2020, 4:40 PM
SAKKURI BHANU PRAKASH
2 odpowiedzi
+ 2
Are you sure? Am getting false only.. Check it again once..
1st Dec 2020, 6:27 PM
Jayakrishna 🇮🇳
+ 1
Thank you Martin Taylor, My test case input is a file input in hackerrank I am getting the answer required but i am a little confused on how i got it. Now I came to know that giving input to Scanner class System.in takes all inputs and we assign variables in required manner .
2nd Dec 2020, 1:58 AM
SAKKURI BHANU PRAKASH