数据类型
1 package com.Lucky.base; 2 3 public class dataType { 4 public static void main(String[] args) { 5 //数据类型 【 基本类型 和 引用类型 】 6 //拓展:==是比较值 ===是比较值和数据类型 7 //1.基本类型 8 //整数类型:byte[1字节 -128到127] 9 // short【2字节 -3万多到+3万多 】 10 // int 【4字节 -20亿到+20亿】 11 // long【8字节 19位数的长度】 12 13 //浮点数类型:float【4字节】 14 // double【8字节】 15 16 //布尔类型 :boolean 17 18 //字符类型:char【2字节】 19 20 21 22 //举例说明: 23 int num1=165656; 24 byte num2=127; 25 short num3=29999; 26 long num4=1656544856L; 27 float num5=1656.1F; 28 double num6=12.236674; 29 char name='A'; 30 boolean res=false; 31 String name1="dbrhg"; 32 33 34 System.out.printf(name1); 35 36 37 System.out.println("////**********///"); 38 //整数拓展 八进制 十六进制 39 int q=10; 40 int w=010; 41 int e=0x10; 42 System.out.println(w); 43 System.out.println(q); 44 System.out.println(e); 45 46 47 48 System.out.println("////*****银行业务[BigDecimal]*****///"); 49 //浮点数类型拓展:银行业务[BigDecimal] 50 float f=0.1f; 51 double test=(double) f; 52 System.out.println(test); //怎么转换都没有用 53 double d=1/(double)10; 54 System.out.println(d); 55 System.out.println(f==d); //false 56 57 float f1=25245535234f; 58 float d1=f1+1; 59 System.out.println(f1==d1); //true 60 ///避免使用浮点数类型 ;有限/大概/存在精度丢失问题 61 62 63 System.out.println("///////////////////////////////"); 64 //字符拓展 65 char c1='A'; 66 System.out.println(c1); 67 System.out.println((int) c1);//强行装换 68 69 70 71 //转义字符 72 // \t制表符 73 // \n换行 74 System.out.println("hoo\nhoo");//换行 75 System.out.println("hoo\thoo");//制表【空格】 76 77 String s1="123"; 78 String s2="123"; 79 System.out.println(s1==s2); 80 81 82 //对象之间不存在相等【引用类型】 83 String s3=new String("123"); 84 String s4=new String("123"); 85 System.out.println(s3==s4); //false 86 87 88 System.out.println("////////////////////////"); 89 //boolean拓展 90 boolean b1=false; 91 if(b1){ 92 System.out.println("Year"); 93 }else{ 94 System.out.println("No"); 95 } 96 } 97 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律