1. 程式人生 > 遊戲 >《魔咒之地》PC版載入快 支援DirectStorage API

《魔咒之地》PC版載入快 支援DirectStorage API

基本語法

註釋

//單行註釋
//單行註釋

/*
  多行註釋
  多行註釋
  多行註釋
*/

/*
*文件註釋
*文件註釋
*/

識別符號和關鍵字

所有的識別符號都應該以字母A(a)-Z(z),美元符($)或者下劃線(_)開始

識別符號不能和關鍵字一樣

常用的關鍵字

abstract assert boolen break byte
case catch char class const
continue default do double else
enum extends final finally float
for goto if implements import
instanceof int interface long native
new package private protected public
return strictfp short static super
switch synchronized this throw throws
transient try void volatile while

資料型別

long型別要在數字後面加L

//整數
        short num1 = 10;
        byte num2 = 20;
        int num3 = 30;
        long num4 = 40L;//long型別要在數字後面加L

float型別要在數字後面加F

//浮點數
float num5 = 1.1F;//float型別要在數字後面加F
double num6 = 1.11111111111;

1. char定義要用單引號,且只能一個字

2. String可以多個字

 //字元
char name1 = '中';//char定義要用單引號,且只能一個字
char name2 = '文';
//字串
String name3 ="哈哈哈哈";//String可以多個字

//布林值:是非
boolean flag1 = true;
boolean flag2 = false;

字元拓展

char c1 = 'a';
char c2 = '中';

System.out.println((int)c1);//強制轉換
System.out.println((int)c2);//強制轉換

輸出結果:

97

20013

這是Unicode碼,每個字元對應一個Unicode碼

Unicode用程式碼表示:'\u0000'—'\uFFFF'(16進位制)

char c3 = '\U0061';  /*16進位制的0061轉化為10進位制是97,對應的字元為a*/
System.out.println(c3);

輸入結果:

a

轉義字元

1、\t 輸出一個tab

2、\n 換行