Scanning Strings

Part E: Scanning Strings

In VS Code, open the file Numbers.java Above the public class Numbers line, add the line:

import java.util.Scanner;

Inside main, add the code:

String numbers = "86 75 309";
Scanner scanner = new Scanner(numbers);

while (scanner.hasNextInt()) {
    int num = scanner.nextInt();
    System.out.println(num);
}
scanner.close();

With your partner, predict what will happen when you run this code. Compile and run the code using the Terminal.

Did it match what you expected?

Before you move on to the next part of the warmup, make sure you add, commit, and push your changes to GitHub. In the Terminal, type:

git add Numbers.java

And then:

git commit -m “xxxx” 

where you replace xxxx with your own commit message, followed by:

git push

You can check your files on GitHub to make sure your commit was successful.