The problem is with 'sc.hasNextInt()' Since there isn't another int after the last entry, the program will not print it. If you change the call from 'hasNextInt()' to 'hasNext()' the code should work (as the final newline character will be read).
You'll note that the following code has a blank space at the end of the input string. You could do something similar and use while sc.hasNext(). On the other hand, you could structure your code differently so that you don't print based on the existence of the next character/int in the input string.
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! 3 + 3.0 = 6 ";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
while (scanner.hasNext()) {
// check if the scanner's next token is an int
System.out.println("" + scanner.hasNextInt());
// print what is scanned
System.out.println("" + scanner.next());
}
// close the scanner
scanner.close();
}
}