// ITI 1120 2010 // Name: Diana Inkpen, Student# 123456 //import java.io.*; /** * This program checks is the sum of the elements in an array exceeds a threshold t * Exercize 6.12 in lecture notes */ class SumArrayExceeds { public static void main (String[] args) { // DECLARE VARIABLES/DATA DICTIONARY int [] a; int t; boolean result; // READ IN GIVENS System.out.println( "Please enter the array:" ); a = ITI1120.readIntLine( ); System.out.println( "Please enter a threshold (an integer):" ); t= ITI1120.readInt(); // CALLS THE ALGORITHM result = sumArrayExceeds(a, t); // PRINT OUT RESULTS AND MODIFIEDS System.out.println( "The result is " + result ); } public static boolean sumArrayExceeds ( int [] x, int t) { // VARABLE DECLARATIONS int n = x.length; int index; // intermediate int sum; // intermediate boolean exceeds; // RESULT //BODY OF THE ALGORITHM sum = 0; for (index = 0; (index < n && sum <= t); index = index +1) { sum = sum + x [index]; } exceeds = (sum > t); // RETURN RESULTS return exceeds; } }