Guest User

Untitled

a guest
Apr 26th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment