// 快捷鍵 ctrl + /數組
/*this
*/ 快捷鍵是:crtl+shift+/spa
/** * * * */ 快捷鍵是:/**+enter接口
主要做用就是給類或者方法,變量生成具體文檔說明的時候使用文檔
有特殊意義的單詞字符串
注意:保留字包含了關鍵字input
abstract assert boolean 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數學
3.1.1 byte(1)it
-128——127class
3.1.2 short(2)
3.1.3int(4)
3.1.4long(8)
通常聲明long類型的時候賦值都要在數字後面加上L
3.2.1float(4)
給float類型賦值的時候後面須要加上F
3.2.2 double(8)
字符在計算機中是不存在在,其實都是由數字關係進行比對轉換而來的
ASCII 97 a 98 b
65 A
結果只能是true或者 false
小的數據類型轉換爲大的數據類型
浮點型與整型之間的轉換
注意轉換以後會丟失精度
數據類型 變量名 = 值; int m = 10;
1.不能和關鍵字衝突 2.只能出現字母數字,$和下劃線_,而且首個字符不能是數字
3.見名知意
4.駝峯規則
變量名和方法名:首字母小寫,若是有多個單詞,其餘單詞首字母大寫
類名:首字母大寫,若是有多個單詞,其餘單詞首字母大寫
注意:標識符大小寫敏感 int a = 19; int A = 20;a和A是不同的
+-*/
取模(取餘)運算符 %
Scanner input = new Scanner(System.in);
System.out.println("請輸入一個四位整數:");
int num = input.nextInt();
System.out.println("你輸入的是:" + num);
int ge = num % 10;
int shi = num / 10 % 10;
int bai = num / 100 % 10;
int qian = num / 1000;
System.out.println("" + ge + shi + bai + qian);
= 右邊的值賦值給左邊
+=
a += 2; //a = a + 2;
-= a -= 4; // a = a - 4; *=
/= %=
a *= 4; // a = a * 4 a /= 4;
a %= 4;
關係運算符 > < >= <= == != 注意:關係運算符 最後的結果都是布爾值 Scanner input = new Scanner(System.in);
System.out.println("請輸入第一個數:");
int a = input.nextInt();
System.out.println("請輸入第二個數:");
int b = input.nextInt();
System.out.println(a != b);
邏輯運算符(短路運算符) && || & | 最終返回的也是boolean的值 通常邏輯運算符都會和關係運算符結合一塊兒使用
&& 當條件所有知足的時候纔會返回true,不然就返回false
並且因爲是短路運算,只有第一個條件可以直接獲得答案,那麼就不會再執行後面的結果
boolean b = 10 > 8 && 9 < 98 && 8 < 10; System.out.println(b); Scanner input = new Scanner(System.in); System.out.println("請輸入小明語文成績:"); int yuwen = input.nextInt(); System.out.println("請輸入小明的數學成績:"); int math = input.nextInt(); boolean flag = yuwen >= 90 && math >= 95; System.out.println(flag);
|| 只要有一個條件知足返回就是true,因爲是短路運算,若是第一個條件知足,後面的就不用再運算了
boolean b = 10 > 8 || 8 < 7; System.out.println(b); Scanner input = new Scanner(System.in); System.out.println("請輸入第一個數:"); int a = input.nextInt(); System.out.println("請輸入第二個數:"); int b = input.nextInt(); boolean flag = ( a + b >= 10 ) && ( a / b > 4 ); System.out.println(flag);
&& & || | ^ !
<< >>(有符號) >>>(無符號)
一個整數(先轉換爲2進制)向右移動一位 00101101 變爲01011010
有符號:11111100 變爲11111110
無符號:11111100 變爲01111110
++ --
++= --= 增量或者減量當即發生
=++ =-- 增量或者減量在語句中變量使用後發生
正負號 new insteanceOf () [] .
同一優先級的運算符,結合次序由結合方向所決定。(意思是從左到右)
簡單記就是: ! > 算術運算符 > 關係運算符 > && > || > 賦值運算符
記不住,就打上()
注意:String類型並非基本數據類型中的一種
String str = "中國真棒!"; System.out.println(str);
注意:只有有字符串的出現 + 就會被認爲是字符串拼接符
String a = "中國,"; String b = "棒棒棒!,牛批!"; String c = a + b; System.out.println(c);