003-006-003

Cast Operator: Average Calculator

Easy

Problem Description

Cast Operator: Average Calculator

Learning Objective: Understand difference between integer division and floating-point division

Calculate sum and average of three integers. Division between int types is integer division, truncating decimal part. However, casting with (double) yields accurate average including decimal part.

Input

Line 1: Integer A (1-100)
Line 2: Integer B (1-100)
Line 3: Integer C (1-100)

Output

Sum: [sum]
Integer Average: [average by integer division (truncated)]
Exact Average: [accurate average (with decimal)]
```java

## Examples

### Example 1: Evenly Divisible
Input:
```java
10
20
30
```java
Output:
```java
Sum: 60
Integer Average: 20
Exact Average: 20.0
```java
Result is same for both integer and real division

### Example 2: Evenly Divisible (Smaller Values)
Input:
```java
10
15
20
```java
Output:
```java
Sum: 45
Integer Average: 15
Exact Average: 15.0
```java
Sum 45÷3=15 divides evenly

### Example 3: Same Result for Integer and Real
Input:
```java
10
11
12
```java
Output:
```java
Sum: 33
Integer Average: 11
Exact Average: 11.0
```java
Sum 33÷3=11 divides evenly.

Test Cases

※ Output examples follow programming industry standards

Input:
10
20
30
Expected Output:
Sum: 60
Integer Average: 20
Exact Average: 20.0
Input:
10
15
20
Expected Output:
Sum: 45
Integer Average: 15
Exact Average: 15.0
Input:
10
11
12
Expected Output:
Sum: 33
Integer Average: 11
Exact Average: 11.0
Input:
1
2
3
Expected Output:
Sum: 6
Integer Average: 2
Exact Average: 2.0
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
// すべての値を加算して適切な式を使って合計結果を計算
int sum = a + b + c;
// 整数除算 平均(小数点以下を切り捨て)
int intAverage = sum / 3;
// キャストによる実除算(正確な平均)
double exactAverage = (double)sum / 3;
System.out.println("Sum: " + sum);
System.out.println("Integer Average: " + intAverage);
System.out.println("Exact Average: " + exactAverage);
}
}

0 B / 5 MB

You have 10 free executions remaining