java练习_大数运算_BigInteger.pdf

上传人:索**** 文档编号:76260903 上传时间:2023-03-08 格式:PDF 页数:4 大小:10.73KB
返回 下载 相关 举报
java练习_大数运算_BigInteger.pdf_第1页
第1页 / 共4页
java练习_大数运算_BigInteger.pdf_第2页
第2页 / 共4页
点击查看更多>>
资源描述

《java练习_大数运算_BigInteger.pdf》由会员分享,可在线阅读,更多相关《java练习_大数运算_BigInteger.pdf(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、/*大数运算*BigInteger*求91 的 92 次方*求它除以 100 的余数*大数运算 Biginteger类的方法调用*/package com.test1;import java.math.*;import java.math.BigInteger;publicclass test100 /*param args*/static BigInteger k=BigInteger.valueOf(1);static BigInteger j=BigInteger.valueOf(91);static BigInteger n;BigDecimal l=new BigDecimal(10

2、0);static BigInteger m=new BigInteger(100);publicstaticvoid main(String args)/TODO Auto-generated method stub/k=BigInteger.valueOf(1);/k=new BigInteger(1);for(int i=1;i=92;i+)k=k.multiply(j);System.out.println(k.toString();/n=k.remainder(m);n=k.remainder(m);System.out.println(n.toString();/java大数运算

3、Biginteger类的方法调用/以下代码与本练习没有必要关系,可以删除class BigIntegerGet public String getAdd(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.add(BigInt2);/加 Str3=BigInt1.toString();return Str3;public String getSubtract(

4、String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.subtract(BigInt2);/减 Str3=BigInt1.toString();return Str3;public String getMultiply(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new

5、BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.multiply(BigInt2);/乘 Str3=BigInt1.toString();return Str3;public String getDivide(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.d

6、ivide(BigInt2);/除 Str3=BigInt1.toString();return Str3;public String getRemainder(String Str1,String Str2)/String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.remainder(BigInt2);/余数 Str3=BigInt1.toString();return Str3;public String

7、getGcd(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.gcd(BigInt2);/最大公约数 Str3=BigInt1.toString();return Str3;public String getPow(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new

8、 BigInteger(Str1);int Int2=Integer.valueOf(Str2);BigInt1=BigInt1.pow(Int2);/方 Str3=BigInt1.toString();return Str3;public String getMod(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.mod(BigInt2);/模 Str3

9、=BigInt1.toString();return Str3;public String getModInverse(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.modInverse(BigInt2);/倒数取模 Str3=BigInt1.toString();return Str3;public String getMax(String Str1,

10、String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.max(BigInt2);/返回较大一个数的值 Str3=BigInt1.toString();return Str3;public String getMin(String Str1,String Str2)String Str3=new String();BigInteger BigInt1=new BigInteger(Str

11、1);BigInteger BigInt2=new BigInteger(Str2);BigInt1=BigInt1.min(BigInt2);/返回较小一个数的值 Str3=BigInt1.toString();return Str3;publicint getHashcode(String Str)int hash=-1;BigInteger BigInt=new BigInteger(Str);hash=BigInt.hashCode();return hash;publicboolean getIsProbablePrime(String Str,int certainty)boolean flag=false;BigInteger BigInt=new BigInteger(Str);flag=BigInt.isProbablePrime(certainty);/素数return flag;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 实施方案

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁