此代碼適用於某些輸入。 但我得到一個NumberFormatError爲更高的輸入值,如1000000. 輸入(採取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());
}
}
}
你可以給你輸入例外嗎?! – SudoRahul
你可以發佈異常的堆棧跟蹤嗎? – Evans
有沒有答案可以回答你的問題?如果是這樣,請將您最喜歡的答案標記爲已解決,如果不是,請提供更多信息。 – Izmaki