logo Practice-It logo

BJP4 Self-Check 6.13: readme2next

Language/Type: Java file processing mystery Scanner
Author: Jared Jones (on 2016/09/08)

Consider a file called readme.txt that has the following contents:

6.7     This file has
        several input lines.

  10 20         30   40

test

What would be the output from the code in the previous exercise if the calls to hasNextLine and nextLine were replaced by calls to hasNext and next, respectively, as shown below?

Scanner input = new Scanner(new File("readme.txt"));
int count = 0;
while (input.hasNext()) {
    System.out.println("input: " + input.next());
    count++;
}
System.out.println(count + " total");
output

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.