logo Practice-It logo

BJP5 Self-Check 6.15: linesAndTokens

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

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
// 1.
Scanner input = new Scanner(new File("brownfox.txt"));
while (input.hasNextLine()) {
    String line = input.nextLine();
    System.out.println(line);
}
// 2.
Scanner input = new Scanner(new File("brownfox.txt"));
while (input.hasNext()) {
    String token = input.next();
    System.out.println(token);
}
1.
2.

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.