You are viewing a single comment's thread. Return to all comments →
In fact, you can shorten it even further (at a potential loss of readability) by including the print statement within the for loop:
for(int i = 1; scan.hasNext(); System.out.println(i + " " + scan.nextLine()), i++);
for(int i=1; scan.hasNext() ; System.out.println(i++ +" "+scan.nextLine()));
That's pretty sweet! Thanks.
That's not very readable code! A while loop is more appropriate.
Thanks for a different a view.
Oh...thats great idea =))
what scan.hasNext do?
it checks,is the scanner has more tokens in its input
for(int i=1;in.hasNext() ;out.println(i++ +" "+in.nextLine()) );
what does Scan.hasNext() exactly means??
And while in the for loop we are not comparing Scan.hasNext() ??
U shall read Scan.hasNext like this.... does "Scan" have next element ?
If it has, it returns TRUE, so while something is TRUE, keep it going. That's why you don't need any comparing.
sorry for being late,scan.hasNext() means after getting one input sacanner will wait for the next input .
Thanks a lot for sharing your knowledge..