// ITI 1120 // Name: Diana Inkpen, Student# 123456 //import java.io.*; /** * This program computes the sum of the elements in an array. * Ex 6.11 in lecture notes */ class SumArray { public static void main (String[] args) { // DECLARE VARIABLES/DATA DICTIONARY int [] a; int result; // READ IN GIVENS System.out.println( "Please enter the array:" ); a = ITI1120.readIntLine( ); // CALLS THE ALGORITHM result = sumArray(a); // PRINT OUT RESULTS AND MODIFIEDS System.out.println( "The sum is " + result ); } public static int sumArray ( int [] x) { // VARABLE DECLARATIONS int index; // intermediate int sum; // RESULT //BODY OF THE ALGORITHM sum = 0; index = 0; while (index < x.length) { sum = sum + x[index]; index ++; } // RETURN RESULTS return sum; } }