004-007-008

Array Length: Calculations with length

Medium

Problem Description

array Length: Calculations with length

In this problem, you will create a program that uses the length property on an integer array {85, 90, 78, 92, 88} to calculate the count, sum, and average, and displays the results to standard output.

Learning Objective: Understand how to use the array's length property to calculate array statistics (sum, average)

Overview

The array's length property returns the number of elements in the array. This can be used for loop termination conditions and average calculations.

Specifications

Implement the following:

  1. Declare an integer array {85, 90, 78, 92, 88} (test scores)
  2. Calculate the sum using a for loop and length
  3. Calculate the average by dividing the sum by length (as double)
  4. Output the count, total, and average on separate lines

Output Format

Count: 5
Total: 433
Average: 86.6

Hint

  • Don't forget to cast to double when calculating the average
  • 433 / 5 = 86 (integer division), 433.0 / 5 = 86.6 (floating-point division)

Test Cases

※ Output examples follow programming industry standards

Input:
Expected Output:
Count: 5
Total: 433
Average: 86.6
Input:
Expected Output:
Count: 5
Total: 433
Average: 86.6
Input:
Expected Output:
Count: 5
Total: 433
Average: 86.6
Input:
Expected Output:
Count: 5
Total: 433
Average: 86.6
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 9 free executions remaining