logo Practice-It logo

BJP4 Self-Check 6.15: linesAndTokens

Language/Type: Java Scanner input File processing
Author: Marty Stepp (added by Melissa Galloway on 2016/09/08)

Given the following file contents, what will be the output from each of the following code fragments?

the quick brown
   fox   jumps

       over
the lazy    dog
// a.
Scanner input = new Scanner(new File("brownfox.txt"));
while (input.hasNextLine()) {
    String line = input.nextLine();
    System.out.println(line);
}
// b.
Scanner input = new Scanner(new File("brownfox.txt"));
while (input.hasNext()) {
    String token = input.next();
    System.out.println(token);
}
a.
b.

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.