We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hey could you please help me with this problem... I am using a while loop just like you but in the output the Hello part is not being printed..
this is my code-->
Scanner sc=new Scanner(System.in);
String s=sc.next();
int i=1;
while(sc.hasNextLine())
{ String s1=sc.nextLine();
System.out.println(i+" "+s1);
i++;
}
Expected Output-->
1 Hello world
2 I am a file
3 Read me until end-of-file.
My output-->
1 world
2 I am a file
3 Read me until end-of-file.
Java End-of-file
You are viewing a single comment's thread. Return to all comments →
Hey could you please help me with this problem... I am using a while loop just like you but in the output the Hello part is not being printed..