Reading Input: Scanner and BufferedReader

Reading input with Scanner: nextInt, nextLong, next.

Problem data arrives on standard input. The simplest way to read it in Java is the Scanner class from the java.util package. The main methods: nextInt() — an integer, nextLong() — a long integer, nextDouble() — a float, next() — one word. Scanner skips spaces and newlines by itself. Press "Input" above the code, enter two numbers separated by a space and run it.
Java

Enter two numbers in the "Input" field, for example: 3 5

Don't forget import java.util.Scanner; on the first line of the file — without it the Scanner class will not be found. Words are read with the next() method:
Java

Enter a name and an age, for example: Azat 15

Scanner is convenient but slow — with large inputs that becomes a problem. We will cover the fast way to read (BufferedReader) in the last lesson of the course. Task: read three numbers and print their arithmetic mean (divide by 3.0 so the result is fractional). Then solve the attached problem "Sum of Two Numbers", get Accepted and mark the lesson as completed.

Practice problems

Доска