日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java中BigInteger的各种方法详解

發布時間:2023/12/15 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java中BigInteger的各种方法详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

顧名思義,BigInteger就是用于處理題目中涉及到大整數的加減乘除運算。

文章目錄

    • ·int 與 BigInteger之間的相互轉化
    • ·錯誤案例:BigInteger 與 int 之間不能直接相互轉化
    • ·BigInteger的常用方法

·int 與 BigInteger之間的相互轉化

import java.math.BigInteger; public class Demo1{public static void main(String[] args){//int 與 BigInteger之間的正確轉換方法://int 轉換為 BigInteger的方法:int p = 1;BigInteger a = BigInteger.valueOf(p);//BigInteger 轉換為 int的方法:BigInteger d = new BigInteger("9");int temp = d.intValue();*/} }

·錯誤案例:BigInteger 與 int 之間不能直接相互轉化

import java.math.BigInteger; public class Demo2{public static void main(String[] args){BigInteger temp = new BigInteger("9");int a = 1;System.out.println(temp+a);} }

·BigInteger的常用方法

import java.math.BigInteger; public class Demo3{public static void main(String[] args){//常用方法:BigInteger temp = new BigInteger("9");BigInteger temp1 = new BigInteger("6");BigInteger temp2 = new BigInteger("-6");//add();-------加法System.out.println(temp.add(temp1));//subtract();-------減法System.out.println(temp.subtract(temp1));//multiply()-------乘法System.out.println(temp.multiply(temp1));//divide()-------相除取整System.out.println(temp.divide(temp1));//remainder()與mod()-------取余System.out.println(temp.remainder(temp1));System.out.println(temp.mod(temp1));//negate()------取相反數System.out.println(temp.negate());//abs()------取絕對值System.out.println(temp2.abs());//min(),max()------取最大與最小值System.out.println(temp1.min(temp2));System.out.println(temp1.max(temp2));//gcd()------取最大公約數System.out.println(temp1.gcd(temp));} } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Java中BigInteger的各种方法详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。