public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("输入一个任意长度字符:");
String str = sc.next();
BigInteger sum = BigInteger.ZERO;
BigInteger[] num = new BigInteger[str.length()];
for (int i = 0; i < str.length(); i++) {
num[i] = new BigInteger((String) str.substring(i, i + 1));
}
for (int i = 0; i < num.length; i++) {
sum = sum.add(num[i]);
}
System.out.print(sum);
}
支持任意字符长度的运算。 |