Reading integers
scanner.nextLine() always gives text, a String, even when the user types digits. To calculate with the number, the text has to be turned into an int. Integer.valueOf(...) does that:
Scanner scanner = new Scanner(System.in);
System.out.println("How old are you?");
int age = Integer.valueOf(scanner.nextLine());
System.out.println("Next year you'll be " + (age + 1) + ".");
29How old are you?
Next year you'll be 30.Reading and converting fit on one line: the inner part, scanner.nextLine(), runs first and gives the text "29", and Integer.valueOf turns it into the number 29. (age + 1 in parentheses is calculated before it's joined to the text; the next module is all about calculating.)
Integer.parseInt(...) does the same job, and you'll see both in Java code. If the text isn't a whole number, for example twenty or 2.5, the program stops with a NumberFormatException.