zoukankan      html  css  js  c++  java
  • JavaSE 基础 第06节 八大数据类型

    2016-06-28

    整型
    1个字节占8位

    1 byte 1字节 -128~127
    2 short 2字节 -32768~32767
    3 int 4字节 正负20亿多一点 用的最多
    4 long 8字节 特别大,当int不够用的时候,才会用long

    package day06;
    
    public class TestFloat {
        
        public static void main(String[] args) {
            int i1=1;//声明int类型变量
            int i2=3;
            float f1=1f;//声明float类型变量
            float f2=3f;
            float result1,result2;//记录结果的变量
            
            result1=i1/i2;//结果应该是0
            result2=f1/f2;//结果应该是0.333333
            
            System.out.println("result1="+result1);
            System.out.println("result2="+result2);
        }
    
    }

    字符型
    5 char 占用2个字节,采用的是Unicode编码格式,支持中文

    package day06;
    
    public class TestChar {
        
        public static void main(String[] args) {
            char char1='a';
            char char2='a'+1;
            char char3='a'-1;
            
            System.out.println("char1="+char1);
            System.out.println("char2="+char2);
            System.out.println("char3="+char3);
            //在Unicode编码表中` a b
        }
    
    }

    浮点型

    6 float 4字节 单精度
    7 double 8字节 双精度 用的最多

    布尔型
    8 boolean
    true 真
    false 假

    package day06;
    
    public class TestBoolean {
        
        public static void main(String[] args) {
            boolean b=true;//声明一个boolean类型变量b
            if(b){
                System.out.println("b="+b+"满足条件,if语句执行");
            }else{
                System.out.println("b="+b+"不满足条件,else语句执行");
            }
        }
    
    }

    【参考资料】

    [1] Java轻松入门经典教程【完整版】

  • 相关阅读:
    装饰器的写法以及应用环境
    面向对象中super的作用
    os与sys模块的作用与常用方法
    python re模块
    python 冒泡排序,二分法
    正则表达式
    python 高阶内置函数
    python 内置函数
    python 生成器和生成器表达式
    python 函数名的应用(第一类对象),闭包,迭代器
  • 原文地址:https://www.cnblogs.com/cenliang/p/5625134.html
Copyright © 2011-2022 走看看