hdu1047 java大整数相加
1 import java.util.*; 2 import java.io.*; 3 import java.math.BigInteger; 4 public class Main { 5 public static void main(String[] args) 6 { 7 Scanner in=new Scanner(System.in); 8 int n=in.nextInt(); 9 while (n-->0) 10 { 11 BigInteger ans=new BigInteger("0"); 12 while (in.hasNext()) 13 { 14 BigInteger tmp=new BigInteger("0"); 15 tmp=in.nextBigInteger(); 16 if (!tmp.equals(BigInteger.valueOf(0))) 17 ans=ans.add(tmp); 18 else 19 { 20 System.out.println(ans); 21 if (n!=0) System.out.println(""); 22 break; 23 } 24 } 25 } 26 } 27 }
-------------多个整数和
1.n-->0
2.equals判断相等
3.区别直接new BigInteger和BigInteger.valueOf
4.输出回车