BigInteger a, b; a = BigInteger.valueOf(b); // a=b; int c; a = BigInteger.valueOf(c); // 类型转换 String s = "111"; a = BigInteger.valueOf(s); // 运行后a==111; a = BigInteger("111"); // 赋值常量 a = sc.nextInteger(); // 赋值输入 a = a.add(b); // a+=b; a = a.subtract(b); // a-=b; a = a.multiply(b); // a*=b; a = a.divide(b); // a/=b; /* 函数里的值也是BigInteger 如果是具体数值 格式:a.add(new BigInteger("1")); 是前面变量 格式:a.add(BigInteger.valueOf(i)); 特殊的 0 1 10 可以用BigInteger.ZEROONETEN; */ if(a.compareTo(b)>0) System.out.println(a>b); if(a.compareTo(b)==0) System.out.println(a==b); if(a.compareTo(b)<0) System.out.println(a<b); remainder(); mod(); // 都是a%b pow(); gcd(); // a^b 最大公约数 abs(); negate(); // 绝对值 相反数 max(); min(); // 定义数组格式 BigInteger array[]=new BigInteger[maxn];
然后BigDecimal
1 2 3 4 5 6 7 8
import java.math.BigDecimal; // 头文件 BigDecimal a, b; a = sc.nextBigDecimal(); a = new BigDecimal(111); a = new BigDecimal(b); // 函数和BigInteger差不太多嗷 就有的语法有的小小区别 System.out.println(a.stripTrailingZeros().toPlainString()); // 这个是 输出时去除多余末尾0 好用!!
近期评论