Multidimensional Array Access
Problem Description
Multidimensional Array Access
In this problem, you will create a program that reads values for a 3x3 two-dimensional array from standard input, accesses specific elements using row and column indices to retrieve scores, and calculates each row's average using integer division, displaying the results to standard output.
Learning Objective: Understand how to read input into a 2D array using Scanner, and access elements by specifying row and column indices
Overview
Read values using Scanner into a 3x3 two-dimensional array, then access specific elements and calculate row averages.
Input Format
Three lines, each containing three space-separated integers (scores for Student A, B, and C across three subjects):
scores[0][0] scores[0][1] scores[0][2]
scores[1][0] scores[1][1] scores[1][2]
scores[2][0] scores[2][1] scores[2][2]
Specifications
- Use
Scannerto read values for a 3x3 two-dimensional integer arrayscoresfrom standard input in row-major order - Perform the following operations in order:
- Print the score for Student B's second subject (index [1][1])
- Print each student's average score, truncated to an integer (use integer division)
Output Format
Student B, Subject 2: [value of scores[1][1]]
Student A average: [average for Student A]
Student B average: [average for Student B]
Student C average: [average for Student C]
Sample Input/Output
Input:
85 92 78
90 88 95
72 80 68
Output:
Student B, Subject 2: 88
Student A average: 85
Student B average: 91
Student C average: 73
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up