Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 0.38 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class whatTest {
  2.  
  3. public static int what (int a[]) {
  4.                 int max = a[0];
  5.                 int pos = 0;
  6.                 int sum = 0;
  7.                 while (pos < a.length) {
  8.                         sum += a[pos];
  9.                         if (sum > max)
  10.                                 max = sum;
  11.                         if (sum < 0)
  12.                                 sum = 0;
  13.                         pos ++;
  14.                 }
  15.                 return max;
  16.         }                      
  17.                
  18.         public static void main (String args[]) {
  19.                 int a[] = {5,3,-10,7,5,-3,4};
  20.                 System.out.println (what(a));
  21.  
  22.         }
  23.        
  24. }