008-005-003

Reference Type Argument: Array Processing Method

Easy

Problem Description

Reference Type Argument: array Processing method

Learning Objective: Understand how methods work with reference types (arrays) as arguments

In this problem, you will create a program that receives an integer array as a method argument, calculates the sum of all elements, and displays the result to standard output.

Define a method (e.g., int calculateSum(int[] array)) that receives an integer array and computes its total. Read the number of elements and each integer from standard input, pass the array to your method, and print the sum. Learn that arrays are passed as reference types.

Input

Line 1: Number of elements n (integer)
Following lines: n integers (one per line)

Output

Total: [sum]

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