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 }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/534170.html
標籤:其他
