首页 > 编程语言 > 详细

Java基础知识强化87:BigInteger类之BigInteger概述和构造方法

时间:2015-09-25 15:52:35      阅读:197      评论:0      收藏:0      [点我收藏+]

1. BigInteger类概述

  可以让超过Integer范围内的数据进行运算

2. 构造方法:

1 public  BigInteger(String  val)

3. 代码示例:

 1 package cn.itcast_01;
 2 
 3 import java.math.BigInteger;
 4 
 5 /*
 6  * BigInteger:可以让超过Integer范围内的数据进行运算
 7  * 
 8  * 构造方法:
 9  * BigInteger(String val) 
10  */
11 public class BigIntegerDemo {
12     public static void main(String[] args) {
13         // 这几个测试,是为了简单超过int范围内,Integer就不能再表示,所以就更谈不上计算了。
14         // Integer i = new Integer(100);
15         // System.out.println(i);
16         // // System.out.println(Integer.MAX_VALUE);
17         // Integer ii = new Integer("2147483647");
18         // System.out.println(ii);
19         // // NumberFormatException
20         // Integer iii = new Integer("2147483648");
21         // System.out.println(iii);
22 
23         // 通过大整数来创建对象
24         BigInteger bi = new BigInteger("2147483648");
25         System.out.println("bi:" + bi);
26     }
27 }

运行效果如下:

技术分享

Java基础知识强化87:BigInteger类之BigInteger概述和构造方法

原文:http://www.cnblogs.com/hebao0514/p/4838254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!