Java Program sum1 by dfhrf555fcg

VIEWS: 19 PAGES: 1

More Info
									                                Java Program sum1.java
                                   Quadratic Maximum
import java.util.*;
public class sum1 {

    public static int maxSubsequenceSum( int [ ] a ) {
     int maxSum = 0;
     int seqStart=0,secEnd=0;
     System.out.println ("seqStart= " + seqStart + " secEnd = " + secEnd);
     int i1=0;
     int i2=0;

     for(int i=0;i<a.length;i++) {
        ++i1;
        int thisSum=0;
        for( int j=i;j<a.length;j++) {
          ++i2;
          thisSum += a[j];
          System.out.println ("thisSum = " + thisSum);
          if(thisSum > maxSum) {
            maxSum=thisSum;
               System.out.println();
               System.out.println ("maxSum = " + maxSum);
               seqStart = i;
               secEnd = j;
               System.out.println ("seqStart= " + seqStart + " secEnd = " + secEnd);
          }
        }
     }
     System.out.println ("i1 = " + i1);
     System.out.println ("i2 = " + i2);
     return maxSum;
    }
    public static void main (String [] args) {
      int b[] = {-2,11,-4,13,-5,2};
      int sum;
      sum = maxSubsequenceSum (b);
      System.out.println("sum = "+sum);
    }
}

								
To top