Java中的資料類型

來源:互聯網
上載者:User

標籤:false   轉換   oid   nal   向上轉型   指定   轉型   執行   類型轉換   

/**Java中的資料類型*/

public class Demo03{
static boolean b; //成員變數:類體內方法體外 範圍是整個類。使用時,可以不賦值,執行其預設值
public static void main(String []args){
System.out.println(Math.PI);
boolean b;//聲明 在一個方法裡 相同變數的聲明只能一次
b = true; //賦值
System.out.println("b的值是:"+b);
b = false;
System.out.println("b的值是:"+b);
final boolean cc = true; //由final進行修飾的量叫常量
System.out.println("c的值是:"+cc);
//cc = false;//錯誤: 無法為最終變數cc分配值
char c =‘a‘;
System.out.println("c:"+c);
char c1 = 97;//ANSI 0-65535
System.out.println("c1:"+c1);
char c2 = ‘\u0000‘;
System.out.println("c2:"+c2);

long l =1L;
float f =1.0f;
double d1 = 1.0;
String name ="王小二";
String dd = name+" "+l+" "+f+" "+d1;
System.out.println(dd);


//類型轉換
byte bb = 104;
int i = bb; //byte-->int 小資料類型會自動向大資料類型轉型
System.out.println("byte小-->int大"+i);

long l1 = 1;
int i1 = (int)l1; //大資料類型向小資料類型轉型,需指定小資料類型承接。布爾類型不能轉換,char類型自動向上轉型為int
System.out.println("long大-->int小"+i1);

float f1 = (float)1.0;
float f2 = 1.0f; //f1於f2同樣作用

//上面已經聲明 char c =‘a‘;
int i2 = c;//char自動轉int
System.out.println("char c=‘a‘-->int:"+i2);
}
}

Java中的資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.