大数模板

 1 import java.util.*;
 2 import java.io.*;
 3 import java.lang.String;
 4 import java.math.BigDecimal;  
 5 import java.math.BigInteger;
 6    
 7 public class Main 
 8 {  
 9     public static void main(String[] args)  
10     {  
11         cin = new Scanner(System.in);
12         while(cin.hasNext()){
13             //循环输入
14             int t = cin.nextInt();
15             while(t-- > 0){
16                 //浮点数
17                 String s1,s2;
18                 BigDecimal big1 = new BigDecimal(s1);
19                 BigDecimal big2 = new BigDecimal(s2);
20                 
21                 big1.add(big2);                        // 加法
22                 big1.subtract(big2);                // 减法
23                 big1.multiply(big2);                // 乘法
24                 num.setScale(scale, BigDecimal.ROUND_HALF_DOWN);    // 四舍五入,保留scale位小数
25                 big1.divide(big2, scale, BigDecimal.ROUND_HALF_UP);    // 除法,保留scale位小数
26                 big1.compareTo(big2);                 //-1小于,0等于,1大于
27                 
28                 //整数
29                 BigInteger a,b;
30                 a=in.nextBigInteger();
31                 b=in.nextBigInteger();
32                 
33                 a.add(b);                //加法
34                 a.subtract(b);            //减法
35                 a.multiply(b);            //乘法
36                 a.divide(b)                //除法
37                 a.mod(b)                //取模
38                 
39                 
40                 int n = input.nextInt();  
41                 double p = input.nextDouble();  
42                 p = Math.pow(p, 1.0/n);    //开方
43                 
44             }
45         }
46     }  
47 }  
原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/9016625.html