biginteger 输入
时间: 2024-02-28 22:45:48 浏览: 69
BigInteger是Java中用于处理大整数的类。它可以处理比long类型范围更大的整数。要使用BigInteger,你需要导入java.math.BigInteger类。然后,你可以使用Scanner类获取用户输入的大整数,并将其传递给BigInteger的构造函数来创建BigInteger对象。之后,你可以使用BigInteger对象的方法来执行不同的操作,例如加法、减法、乘法、除法、取模和求最大公约数等。下面是一个示例代码,展示了如何使用BigInteger进行大整数运算:
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
String c = reader.next();
String d = reader.next();
BigInteger a = new BigInteger(c);
BigInteger b = new BigInteger(d);
System.out.println(a.add(b)); // 相加
System.out.println(a.subtract(b)); // 相减
System.out.println(a.multiply(b)); // 相乘
System.out.println(a.divide(b)); // 相除
BigInteger[] e = a.divideAndRemainder(b); // 商和余数
System.out.println(e); // 取模
System.out.println(a.gcd(b)); // 最大公约数
}
}
请提出你的
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)