高精度练习

 

package Deom1;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.SortedMap;
//加法练习
public class lx {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
String str = sc.next();
BigInteger b = new BigInteger(s);  //BigInteger继承自Number类,可表示任意长度的整数。BigInteger用等号可以直接进行复制,而不是引用地址
BigInteger big = new BigInteger(str);
System.out.println(b.add(big));
}
}

package Deom1;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.SortedMap;
//乘法练习
public class lx {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
BigInteger a = sc.nextBigInteger();
BigInteger b = sc.nextBigInteger();
BigInteger c = a.multiply(b);
System.out.println(c);
}
}


posted @ 2020-07-19 07:29  筆尖下的沉默  阅读(108)  评论(0编辑  收藏  举报