| Token | For | Notes |
|---|---|---|
%s | String / Object | toString |
%d | integer types | Not float |
%f | float / double | Not int |
%n | newline | Prefer over \n in formats |
%% | percent sign |
System.out.printf("%s %04d%n", "id", 7);
System.err.println("usage: java App <file>");
| Call | Reads |
|---|---|
next() | token (whitespace) |
nextInt / nextDouble | token, parsed |
nextLine() | rest of line, may be empty |
hasNextInt() | lookahead, no consume on false |
int age = in.nextInt(); in.nextLine(); // leftover newline String name = in.nextLine(); // or always lines int age = Integer.parseInt(in.nextLine().trim());
Scanner on System.in.Scanner on a file (try-with-resources).args in main is never null; check args.length.~ Good luck with your revision! ~