此代码适用于某些输入。但是对于更高的输入值(例如 1000000),我得到一个 NumberFormatError。输入(用于 s[])的范围为 1-2000000 可能是什么原因?
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
try
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int no=Integer.parseInt(read.readLine());
String s[]=read.readLine().split(" ");
int result=0;
for(int i=0; i<no; i++)
{
result+= Integer.parseInt(s[i]);
if(result<0)
result=0;
}
System.out.println(result);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
}