public static int MSA(int[] ar) { int[] arr = new int[ar.length]; int msa = 0; arr[0] = ar[0]; for (int i = 1; i < ar.length; i++) { if (arr[i-1]>= 0) arr[i] = arr[i - 1] + ar[i]; else arr[i] = ar[i]; } for (int i=0;i<ar.length;i++) { System.out.println(arr[i]); if (arr[i] > msa) msa = arr[i]; } return msa; }