Average of Three Integers
Programming Basics · Java
TASK
Problem
Read three integers and print their arithmetic mean as a decimal number.
EXAMPLE
Example
3 6 9
6.0
LIMITS
Constraints
-10^6 ≤ a, b, c ≤ 10^6
LEARN
Theory for this problem
+
The core idea of **Average of Three Integers** is to model the requested operation directly: Read three integers and print their arithmetic mean as a decimal number. The reference solution uses `Scanner` for input. Keep only the state needed for this result, choose numeric types that cover the stated bounds, and preserve the exact input/output contract. This makes the solution easier to verify on boundary cases and avoids unrelated work.
NEED HELP?
Hints
+
['Follow the statement for **Average of Three Integers** literally and identify the smallest state needed to produce its output.', 'The reference solution relies on `Scanner` for input; test the smallest allowed input and one boundary case from the constraints.']
ANSWER
Solution
+
// CodeMaster — Average of Three Integers
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
double average = (a + b + c) / 3.0;
System.out.println(average);
}
}