Java 大数相乘.Wrong answer!Problem Description In this problem,y

问题描述:

Java 大数相乘.Wrong answer!Problem Description In this problem,you will be concerned with int
import java.math.*;
import java.util.*;
public class Main{
static BigInteger a,b;
public static void main(String[] args){
Scanner c=new Scanner(System.in);
Scanner d=new Scanner(System.in);
while(c.hasNext()){
a=c.nextBigInteger();
b=d.nextBigInteger();
System.out.println(a.multiply(b));
}
}
}
Problem Description
In this problem,you will be concerned with integers with very large numbers of digits.You must write code which will repeatedly accept (until end of file) two lines each containing an unsigned integer,and output the product of the two input unsigned integers.The output must not contain any leading zeros.
You can assume that each integer will contain at most 80 digits.The input ends with an end of file.
Sample Input
0342
1298
12
3
Sample Output
443916
36
1个回答 分类:综合 2014-10-28

问题解答:

我来补答
问题主要在这里
while(c.hasNext()){
a=c.nextBigInteger();
b=d.nextBigInteger();
System.out.println(a.multiply(b));
}
根据题意,需要换行(accept (until end of file) two lines ),两行
而你的程序是无需换行的,你应该使用scan的nextLine方法,如下
while(c.hasNextLine()){
a=new BigInteger(c.nextLine());
b=new BigInteger(c.nextLine());
System.out.println(a.multiply(b));
}
再问: 还是wrong answer。。
 
 
展开全文阅读
剩余:2000