識別符號和資料型別
阿新 • • 發佈:2021-08-23
所有識別符號都應該以字母(A-Z或者a-z),美元符($)或者下劃線( _ )開始。
識別符號大小寫敏感。
可以使用中文命名,但一般不建議去使用。
不能用關鍵字作為變數名或方法名。
public class Demo04 {
public static void main(String[] args){
String a="hello";
int b=10;
System.out.println(a);
System.out.println(b);
}
}
強型別語言 //八大基本資料型別
int a=10;
byte b=20;
short c=30;
long d=40;//long型別數字後面加l
//小數,浮點數
float e=50.1f;//float要在數字後面加f
double f=3.1415926;
//字元
char name='國';
//字串,String不是關鍵字,類
//String name="蠟筆小新";
//布林值
boolean flag=true;
//boolean flag=false;
除了八大資料型別之外其餘都是引用資料型別
//整數拓展: 進位制 二進位制0b 十進位制 八進位制0 十六進位制0x
int i1=10;
int i2=010;//八進位制0
int i3=0x10;//十六進位制0x 0~9 A~F 16
System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
public class Demo {
public static void main(String[]args){
String s1=new String("hello world!") ;
String s2=new String("hello world!") ;
System.out.println(s1==s2);//false
String s3=("hello world!") ;
String s4=("hello world!") ;
System.out.println(s3==s4);//true
}
}