作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/18 13:09:35
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
Java 大数相乘.Wrong answer!Problem Description In this problem,y
问题主要在这里
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。。