Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2012 18:14
Show Gist options
  • Save anonymous/2925600 to your computer and use it in GitHub Desktop.
Save anonymous/2925600 to your computer and use it in GitHub Desktop.
public class CubicTest {
static int[] aSequence = {-1,11,-4,13,-5,2} ;
public static void main(String[] args) {
System.out.println( "Total area = " + CubicSeq.maxSubsequenceSum(aSequence));
System.out.println( /*want to print counter value here*/ );
System.out.println( /*want to print sequence of integers here*/ );
}
}
public class CubicSeq
{
public static int maxSubsequenceSum( int [ ] a )
{
int maxSum = 0;
int seqStart;
int seqEnd;
int Ctr = 0;
for( int i = 0; i < a.length; i++ )
for( int j = i; j < a.length; j++ )
{
int thisSum = 0;
Ctr = Ctr++;
for( int k = i; k <= j; k++ )
thisSum += a[ k ];
if( thisSum > maxSum )
{
maxSum = thisSum;
seqStart = i;
seqEnd = j;
}
}
return maxSum;
}
public String toString() {
return //how do I send Ctr value?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment