首页 > 专题系列 > Java解POJ > POJ 2389 Bull Math [解题报告] Java
2013
11-11

POJ 2389 Bull Math [解题报告] Java

Bull Math

问题描述 :

Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers … or so they say. Farmer John wonders if their answers are correct. Help him check the bulls’ answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros).

FJ asks that you do this yourself; don’t use a special library function for the multiplication.

输入:

* Lines 1..2: Each line contains a single decimal number.

输出:

* Line 1: The exact product of the two input lines

样例输入:

11111111111111
1111111111

样例输出:

12345679011110987654321

解题代码:

import java.io.BufferedInputStream;   
import java.math.BigInteger;   
import java.util.Scanner;   
  
/**  
 *  
 * poj2389  
 * @author NC  
 */  
public class Main {   
  
    public static void main(String[] args) {   
        Scanner scan = new Scanner(new BufferedInputStream(System.in));   
        if (scan.hasNext()) {   
            BigInteger a = scan.nextBigInteger();   
            BigInteger b = scan.nextBigInteger();   
            System.out.println(a.multiply(b));   
        }   
    }   
}