• java新手笔记2 数据类型


    1.注释

    /**  doc注释
    *    类说明信息
    */
    //声明类  文件名与类名一致
    public class World {//类定界符
    //声明方法 main方法
        public static void main(String[] args) {
             System.out.println("World World!");
             //System.out.println("welcome java world!");
             //注释的代码不执行  单行注释
    
          /*  多行注释
          System.out.println("World World!");
          System.out.println("World World!");
          System.out.println("World World!");
          System.out.println("World World!");
          */
        }
    }
    

     2.变量

    public class InputDemo {
    
        public static void main(String[] args) {
          //输出 
          System.out.println("TR21" );
          System.out.print("javase
    ");
          System.out.printf("%-5d%d  %.5f
    ",15,3,3.14);
    
          System.out.println(""大家好" xml	oracle javase");
          int a ;//声明变量
          a = 20;//赋值
          int b = 10;
    
          a = a + b;
          System.out.println("a = " + a);//变量不能同名
          final double PI = 3.14;//常量 final
          //PI = 3.15;
          System.out.println("PI = " + PI);
        }
    
    }
    

     3.数据类型

    public class DataDemo {
    
        public static void main(String[] args) {
           //System.out.println("Hello...");
           int _a3 = 10;
           //整型  byte short int  long
           int a = -5;//3.14;
           System.out.println(Integer.MAX_VALUE);
           short b = 20;
           System.out.println(Short.MAX_VALUE);
           long c = 123;
          System.out.println(Long.MAX_VALUE);
          byte d = 127;
          System.out.println("d = " + d);
          //d = 128;
          c = 1234567890123456L;//默认整型 转换long类型
          //浮点型
          float f = 3.14f;//默认double
          double dou = 3.14;
          System.out.println("f = " + f);
          System.out.println("dou = " + dou);
    
          char ch = 'A';
          System.out.println("ch = " + ch);
    
          ch = '中';//变量赋值
          System.out.println("ch = " + ch);
    
          boolean boo = true;//false
    
          int num1 = 123;
          int num8 = 010;
          int num16 = 0xa;
          System.out.println("num1 = " + num1);
          System.out.println("num8 = " + num8);
          System.out.println("num16 = " + num16);
        }
       
    }
    

     4.数据类型转换

    public class DataConvert {
    
        public static void main(String[] args) {
          
           int a = 10;
           long b = a;//隐式类型转换  低精度--》高精度
           byte c = (byte)b;//强制类型转换
           
          System.out.println("a = " + a);
          System.out.println("b = " + b);
          System.out.println("c = " + c);
          long result = c + b + a;
          System.out.println("result = " +  result);// long
          
        }
    
    }
    
  • 相关阅读:
    String和inputstream互转【转文】
    shell学习笔记
    如何实现网页标题的闪动提示
    JAVAWEB项目如何实现验证码
    Oralce数据库的优化(面试必问题)
    sqlldr 学习总结1
    各种浏览器的Hack写法(chrome firefox ie等)
    存储过程
    App Store那些事儿
    JBMP学习引导
  • 原文地址:https://www.cnblogs.com/feilongblog/p/4656419.html
Copyright © 2020-2023  润新知