用大数存储就OK
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
BigInteger sum=BigInteger.ZERO;
while(true) {
BigInteger a=sc.nextBigInteger();
if(a.equals(new BigInteger("0"))) {
break;
}
sum=sum.add(a);
}
System.out.println(sum);
}
}