用Java将大整数解析并将其格式化为八进制
首先,获取两个BigInteger对象并设置值。
BigInteger one, two;
one = new BigInteger("99");现在,将BigInteger对象“两个”解析为Octal。
two = new BigInteger("1100", 8);
String str = two.toString(8);上面,我们使用了以下构造函数。在此,八进制的基数设置为8。适用于BigInteger构造函数和toString()方法。
BigInteger(Stringval,intradix)
此构造函数用于将指定基数中的BigInteger的String表示形式转换为BigInteger。
以下是一个例子-
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigInteger one, two;
one = new BigInteger("99");
// parsing BigInteger object "two" into Octal
two = new BigInteger("1100", 8);
String str = two.toString(8);
System.out.println("Result (BigInteger) : " +one);
System.out.println("Result after parsing : " +str);
}
}输出结果
Result (BigInteger) : 99 Result after parsing : 1100
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短