Java基礎資料型別 (Elementary Data Type)

來源:互聯網
上載者:User

標籤:oat   ble   預設   概覽   out   height   type   body   logs   

1.概覽

基本類型 大小 最小值 最大值 封裝類型 定義標誌
boolean ~ ~  ~ Boolean ~
char 16bits Unicode0 Unicode2^16-1 Character ~
byte 8bits -128 +127 Byte ~
short 16bits -2^15 +2^15-1 Short ~
int 32bits -2^31 +2^31-1 Integer ~
long 64bits -2^63 +2^63-1 Long L
float 32bits IEEE754 IEEE754 Float f
double 64bits IEEE754 IEEE754 Double d
void ~  ~  ~  Void ~
 2.成員變數預設值
基本類型 預設值
boolean false
char ‘\u0000‘ (null)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d

 

3.高精度數字
  • BigInteger 支援任意精度的整數
  • BigDecimal 支援任意精度的定點數
package cn.lz.base;import java.math.BigDecimal;import java.math.BigInteger;/** *  * 高精度數字 * @author lzzz * */public class J17100802 {    public static void main(String[] args) {        BigInteger a1 = new BigInteger("19181716151413121110987654321");        BigInteger a2 = new BigInteger("12345678910111213141516171819");        // 加法        System.out.println(a1.add(a2)); // 31527395061524334252503826140        // 乘法        System.out.println(a1.multiply(a2)); // 236811308550240594910066199325923006903586430678413779899     // int a3 = 12345678910111213141516171819;         /*         * Exception in thread "main" java.lang.Error: Unresolved compilation problem:          * The literal 12345678910111213141516171819 of type int is out of range          */        BigDecimal b1 = new BigDecimal("12345678910111213141516171819.12345678910111213141516171819");        BigDecimal b2 = new BigDecimal("12345678910111213141516171819.12345678910111213141516171819");        // 乘法        System.out.println(b1.multiply(b2)); // 152415787751564791571474464065423486394871076136159258042.2627449915719520852517428216262375170639839780304729768761    }}

 

Java基礎資料型別 (Elementary Data Type)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.