大数相加模板(Java)

高位(1000位相加)的问题,精确度高.

import java.math.BigInteger;
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		BigInteger a= in.nextBigInteger();
		BigInteger b= in.nextBigInteger();
        System.out.println(a.add(b));
	}
}

扩展

import java.math.BigInteger;
import java.util.Scanner;
public class MainA{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		BigInteger a= in.nextBigInteger();
		BigInteger b= in.nextBigInteger();
		System.out.println(a.add(b));
		//System.out.println(a.subtract(b));//大数相减 
		//System.out.println(a.multiply(b));//大数相乘
        //System.out.println(a.mod(b));//大数取MOD
	}
}
发布了73 篇原创文章 · 获赞 27 · 访问量 1243

猜你喜欢

转载自blog.csdn.net/queque_heiya/article/details/103789458
今日推荐