006-002-010
Nested For: 2D Array Processing
Hard
Problem Description
Nested For: 2D array Processing
In this problem, you will create a program that reads the number of rows, columns, and array elements from Scanner, then uses nested for loops to output each row's elements and calculate the total of all elements.
Learning Objective: Understand how to process 2D arrays using nested for loops
Overview
Create a program that builds a 2D array from standard input, outputs all elements, and calculates the total.
Input Format
R C
a[0][0] a[0][1] ... a[0][C-1]
a[1][0] a[1][1] ... a[1][C-1]
...
- Line 1: number of rows R and columns C (space-separated)
- Next R lines: C integers per line (space-separated)
Output Format
Row 1: a[0][0] a[0][1] ...
Row 2: a[1][0] a[1][1] ...
...
Total: sum
Example
Input:
2 3
1 2 3
4 5 6
Output:
Row 1: 1 2 3
Row 2: 4 5 6
Total: 21
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