Average of Two Integers
Easyjava
Read two integers and print their average as a decimal with exactly two places. Because int / int drops the fraction, you must divide by 2.0.
Input: two integers separated by whitespace.
Output: one line — the average, two digits after the decimal point.
Example 1
Input
7 2
Output
4.50
- -1000000 <= a, b <= 1000000
Hint 1
(a + b) / 2.0 keeps the fraction; (a + b) / 2 would not.
Hint 2
String.format(Locale.US, "%.2f", value) prints two decimal places with a dot.
The sum of two ints is an int; dividing it by 2.0 (a double) forces floating-point division so the .5 is not lost. Format the result to two decimals.