Description
现在有很多字符串,由空格和回车风格。这些字符串有的能正常转换为整数,有的不能。现在要求所有字符串中能正常转换成整数的数的和。
Input
很多字符串。
Output
输出一个整数。参加样例
Sample Input
200 40 40too 60
300 dkjd345 100 sse
Sample Output
700
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int sum = 0, n;
while (in.hasNext()) {
try {
String str = input.next();
n = Integer.parseInt(str);
sum = sum + n;
}
catch (NumberFormatException e)
{
}
}System.out.println(sum);
}
}