Code:

import java.io.*;
import java.util.*;
class Comp2004{
static int[]results;
public static void main(String[] args){
//write a method which returns the largest sum of any consecutive integers in the array
int []num = {27,6,-50,21,3,14,16,-8,42,33,-21,9};
int []results = new int[100];
int val = LargestSum(num,results);
System.out.println("The largest value is :"+ val);
}//main
public static int LargestSum(int[]num,int[]results){
int x = 2;//start for loop to run twice,then 3 times etc.
int n = num.length;
int sum = 0;
int large = 0;
int j = 0;
while(x < n){
for(int i = 0; i < x; i++){
sum = sum + (num[i] + num[i + 1]);
}
results[j] = sum;
if(results[j] > results[large]) large = results[j];
x++;
j++;
}//end while
return large;
}//end function
}//class

Problem

I know the largest consecutive sum is 115 by adding up 21, -3, 14, 16, 8, 42 and 33;

The code is not generating an error but the result is incorrect. I connot figure what is wrong. Help!