• java基本类型-八大基本数据类型(4类8种)


    Java是一个强类型语言
    就是必须要先申明是什么类型的,才可以定义,如:

    public class Var {
        public static void main(String[] args) {
            int i = 1;
            //  不能写 i = 1;
            System.out.println(i);
        }
    }
    

    修改变量的值

    public class Var {
        public static void main(String[] args) {
            boolean b = true;   //定义变量
            b = false;          //修改变量
            System.out.println(b);  //输出变量
        }
    }
    
    1. 逻辑类型(true,false)
      1)boolean(布尔类型),取值范围为true/false
      public class Var {
          public static void main(String[] args) {
              boolean b = true;
              boolean b2 = false;
              // boolean d = 2; 不能这样表示
          }
      }
      
    2. 整型(byte、short、int、long)
    • int(整型)取值范围:-2147483648~2147483647
      public class Var {
      public static void main(String[] args) {
          int i = 2147483647;
          int g = 2147483648; //超过范围,不能这样表示
      }
      }
      
      
    1. 浮点型
      • float(单精度浮点型)
      • double(双精度浮点型,小数位比较多,计算钱的时候用BigDecimal)
    2. 字符型
      • char:char类型的变量,赋值的时候长度有且只有一位
        public class Var {
          public static void main(String[] args) {
              char s = '1';
              char s2 = '22'; //这样表示就是错误的语法
          }
      }
      
    1.作者:yanzi_anqi
    3.本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    一种client同步server数据的方案
    nodejs package.json解释
    node.js JS对象和JSON字符串之间的转换
    setInterval的用法
    ActiveMQ 入门Nodejs版
    ActiveMQ + NodeJS + Stomp 极简入门
    为什么 ++[[]][+[]]+[+[]] = 10?
    Child Process模块
    phantomjs 解码url
    PhantomJSのメモいろいろ
  • 原文地址:https://www.cnblogs.com/yanzi-anqi/p/14976636.html
Copyright © 2020-2023  润新知