天天看點

變量的定義

public static void main(String[] args) {
        String s1=new String("ok");
        String s2=new String("ok");
        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
        int s=0x1f;//以0x 開頭,單個數值從0-9,A-F
        int s3=023;//以0開頭,八進制
        System.out.println(s3);
        byte e=23;
        int s4=0b0101;//二進制,以0b開頭
        int s5=76;
        long s6=6;//隐式轉換
        long s7=6L;//常量後面可以跟L,l變成長整型
//        浮點型,單精度,雙精度,科學計數法
        float f1=5.6F;//單精度常量後面必須加F,f
        double f2=8.8;
        double f3 =3e4;
        double f4=.5e-2;//0.5可以寫成.5
        System.out.println(f3);
        char ch='\n';//轉義字元:\   \n換行  \r輸入光标回到行的開頭   \t Tab
        String ks="o"+ch+"k";
        System.out.println(ks);
        char ch1=76;
        System.out.println(ch1);
//        alt+回車:throw
 
    }      

布爾類型的預設值是false;

其餘的7種基本類型預設值:

byte是 (byte)0;

short是 (short)0;

int是 0;

long是 0L;

float 是0.0f;

double 是0.0d;

char是 \u0000。

繼續閱讀