
正文
超运算java代码,基于java的计算器实现代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java程序代码求助关于HugeInteger(最大数)的四则运算,题目如下
错误是因为你的HugeInteger类里需要定义好多方法,但是你的HugeInteger类中都没有,我把你用到的这些方法的类型与作用说出来,你自己在HugeInteger类里面写。
1、void parse(String a) 把String a转换为HugeInteger
2、String toString() 返回HugeInteger的字符串表达形式
3、void add(HugeInteger other) 把other加到当前HugeInteger对象上
4、void substract(HugeInteger other) 用当前对象减去other
5、boolean isZero() 判断当前对象是否为0
6、boolean isNotEqualTo(HugeInteger other) 判断当前对象与other是否相等
7、boolean isGreaterThan(HugeInteger other) 判断当前对象是否比other大
8、boolean isLessThan(HugeInteger other) 判断当前对象是否比other小
9、boolean isGreaterThanOrEqualTo(HugeInteger other) 判断当前对象是否大于等于other
10、boolean isLessThanOrEqualTo(HugeInteger other) 判断当前对象是否小于等于other
相关问答
Q1: 怎样利用Java实现10位数的100次方的计算,求具体代码。谢谢!!!!
超过long的大小的时候要用到
java.math.BigInteger; 这个类
这个类本身并不是数学计算,而是字符拼接模拟数学计算的显示效果。
计算的结果可以以字符串的形式输出。
代码部分:(main方法中)
BigInteger bi =new BigInteger("7894561230");
for(int i=0;i5;i++){ //5次方 理论上可以100次 但是会计算N久
bi = bi.multiply(bi);//multiply 表示乘法 add + ,sub -, div 是除
}
System.out.println(bi); //输出到屏幕看下结果
Q2: java运算
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int num=1;
int countRight=0;
int countError=0;
while(num5){
Random rnd = new Random();
int num1=rnd.nextInt(100);
int num2=rnd.nextInt(100);
System.out.println("问题:"+num1+"+"+num2+"=");
System.out.print("请输入答案:");
int answer=input.nextInt();
int total=num1+num2;
if(answer==total){
countRight++;
}else{
countError++;
}
num++;
}
System.out.println("您答对了"+countRight+"道题,答错了"+countError+"道题。");
}
Q3: java中如何实现超过整数范围的数据之和与乘积
/*
* BigInteger:可以让超过Integer范围内的数据进行运算
*
* 构造方法:
* BigInteger(String val)
*
/
import java.math.BigInteger;
/*
* public BigInteger add(BigInteger val):加
* public BigInteger subtract(BigInteger val):减
* public BigInteger multiply(BigInteger val):乘
* public BigInteger divide(BigInteger val):除
* public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
*/
public class BigIntegerDemo {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("100");
BigInteger bi2 = new BigInteger("50");
// public BigInteger add(BigInteger val):加
System.out.println("add:" + bi1.add(bi2));
// public BigInteger subtract(BigInteger val):加
System.out.println("subtract:" + bi1.subtract(bi2));
// public BigInteger multiply(BigInteger val):加
System.out.println("multiply:" + bi1.multiply(bi2));
// public BigInteger divide(BigInteger val):加
System.out.println("divide:" + bi1.divide(bi2));
// public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
BigInteger[] bis = bi1.divideAndRemainder(bi2);
System.out.println("商:" + bis[0]);
System.out.println("余数:" + bis[1]);
}
}
Q4: 怎么写java代码?
只要自己的电脑安装了jdk环境,任何地方都可以进行java代码的编写的,记事本也可以。







