数组子数组之和最大(2,3)
package diyibufen;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class erbufen {
public static int max(int a,int b) {
return a>b?a:b;
}
public static void TurnToEnd() {
System.out.println("ERROR!!!");
System.exit(0);
}
public static void main(String[] args) throws IOException {
int[] a=new int[10010];
int[] res=new int[10010];
int n;
String[] s=new String[10000];
BufferedReader br= new BufferedReader(new FileReader("E:/Java/diyibufen/input.txt"));
s=br.readLine().split(",");
n=Integer.parseInt(s[0]);
s=br.readLine().split(",");
if(s.length!=n) {
TurnToEnd();
}
for(int i=1;i<=n;i++) {
if(s[i-1].length()<9) {
a[i]=Integer.parseInt(s[i-1]);
}else {
TurnToEnd();
}
}
int k=a[0];
for(int i=1;i<=n;i++) {
if(res[i-1]<0) res[i]=a[i];
else res[i]=a[i]+res[i-1];
if(res[i]>1e9||res[i]<-1e9) {
TurnToEnd();
}
k=max(k,res[i]);
}
System.out.println(k);
}
}