BigInteger Uva

import java.io.*;  
import java.math.BigInteger;  
import java.util.*;  

public class Main {
    public static void main(String[] args)
    {
        BigInteger ans,Zero;

        Zero = BigInteger.ZERO;
        ans = BigInteger.ZERO;
        Scanner cin = new Scanner(System.in);  
        while(cin.hasNextBigInteger())
        {
            BigInteger temp = cin.nextBigInteger();  
            if(temp.equals(Zero)) break;
            ans = ans.add(temp);
        }
         System.out.println(ans);
    }
}
View Code
import java.io.*;  
import java.math.BigInteger;  
import java.util.*;  

public class Main {
    public static void main(String[] args)
    {
        BigInteger a,b;

        Scanner cin = new Scanner(System.in);  
        
        while(cin.hasNextBigInteger())
        {
            a = cin.nextBigInteger(); 
            b = cin.nextBigInteger();
             System.out.println(a.multiply(b));
        }
        
    }
}
View Code
import java.math.BigInteger;  
import java.util.*; 

public class Main {
    public static void main(String[] args)
    {
        BigInteger a,b,c;
        String p,q;
        Scanner cin = new Scanner(System.in);  
        
        while(cin.hasNext())
        {
            p = cin.next(); 
            String s = cin.next();
            char ch = s.charAt(0);
            q = cin.next();
            
            
            System.out.println(p+" "+s+" "+q); 
            a = new BigInteger(p);
            b = new BigInteger(q);
            
            if(ch == '+')
                c = a.add(b);
            else
                c = a.multiply(b);
            
            
            if(a.bitLength() > 31)
            {
                System.out.println("first number too big");
            }
            if(b.bitLength() > 31)
            {
                System.out.println("second number too big");
            }
            if(c.bitLength() > 31)
            {
                System.out.println("result too big");
            }
        }
    }
}
View Code

 

posted @ 2013-10-31 20:17  等待最好的两个人  阅读(190)  评论(0编辑  收藏  举报