java 基礎資料型別 (Elementary Data Type)

來源:互聯網
上載者:User

標籤:

//整型
public static void TheNumber(){
  byte byte1=127;//1位元組 8位 -128——127
  short shorT=1200;//2 位元組 16位
  int num1=1200;//8位元組 32位
  long num2=121L;//8 位元組 64位 long類型建議加L
  int num3=0b0000_0000_0000_0000_0000_0000_0000_0011;//jdk1.7 二進位表示 3
  int num4=1234_1234;//jdk1.7 12341234
  System.out.println(num3);
}
//進位轉換
public static void scaleNumber(){
  int num1=10;
  String num2=Integer.toBinaryString(num1);//轉為2進位
  String num3=Integer.toOctalString(num1);//轉為八進位
  String num4=Integer.toHexString(num1);//轉為16進位

}
//浮點類型 浮點類型常量預設是double
public static void floating(){
  double d=3.14; //8 位元組
  float f=3.14F;// 4位元組
  double d2=10e-2;//科學計數法 0.1
  //浮點數 會損失精度 如果需求要求嚴格就使用 浮點類型常量預設是double
  float f1=0.1f;
  double d3=1/10;
}
//字元類型
public static void character(){
  char c1=‘q‘;
  char c2=‘中‘;//unicode 2個位元組 :0-65535
  char c3=‘\‘‘;//\是轉意字元 輸出 ‘
  char c4=‘\n‘;//轉意 表示換行
  char c5=‘a‘;
  int n=c5+2;//99 ASCII碼
  char c6=(char)n;//整數轉為 char
  //迴圈 列印a-z
  for(int i=0;i<26;i++){
    char temp=(char)(‘a‘+i);
    System.out.println(temp);
  }
  //在java中 字串被定義為String類型了
  String str="ABCDEFG";
}
//是/否
public static void whether(){
  boolean boo=false;// 1位元組
}

java 基礎資料型別 (Elementary Data Type)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.