zoukankan      html  css  js  c++  java
  • Java 基本数据类型

    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
        }
    }
  • 相关阅读:
    微服务简介
    Apache httpd.conf
    搭建PHP开发环境
    搭建Apache开发环境
    Swift 项目编译优化(一)
    用Flutter 写一个简单页面
    Sign In With Apple(一)(转)
    Xcode DeviceSupport
    MQTT初始篇笔记整理
    UITableView使用过程中可能遇到的问题
  • 原文地址:https://www.cnblogs.com/larobyo/p/7638182.html
Copyright © 2011-2022 走看看