Two files contain the following Java code (exactly as it appears here, there is nothing else in the files). The files are compiled by the Java compiler and the resulting Java program is run.
Here is the first file:
public class PosArraySum { public static int pos_array_sum(int a[]) { int i, sum = 0; for (i = 0; i < a.length; i++) { if (a[i] > 0) sum = sum + a[i]; } return sum; } }
Here is the second file:
public class PosArraySumDemo { static int[] half_neg = {1,1,1,-1,-1,-1}; public static void main(String argv[]) { System.out.println("The result for half_neg is " + PosArraySum.pos_array_sum(half_neg)); } }
for
statement is changed from i = 0
to i = 3