Operator:
Emphasis: + + and--operators;
a++ (a--): The first value of a is taken into the calculation, after the calculation is completed, then the value of A is +1 (-1);
++a (--A): First the value of a +1 (-1) operation, and then +1 (-1) after the new a value into the calculation;
Escape characters:
Format: \+ letter or match
In general:
\ nthe line break
\ t tab
\b Backspace key
\ r Press the ENTER key
logical operators
With: &, false on one side, true on both sides;
Or: |, either side is true on both sides and false on both sides;
XOR: ^, with or (|) A bit different: when both sides are true, the result is false----true^true=false
Double and: && When false to the left, no operation is performed on the right.
Double or: | |, when the left is true, no operation is performed on the right.
Bitwise operators: (essentially binary operations, that is, converting the corresponding character numbers into binary operations)
>>: Shift to right gradually decreases. (Divide by 2 to move the number of bits to the power).
<<: Shift to left gradually increases. (multiplied by 2 to move the number of bits to the power).
3 greater than right shift >>>, and the highest bit with 0 complement.
2 greater than number right shift >>, and the highest bit is what is used to complement the position.
Judgment statement:
1 /*2 Requirements: Enter a month to print out the relative seasons and months.3 */4 classIfTest25 {6 Public Static voidMain (string[] args)7 {8 intnum=10;9 Ten if(num==3| | num==4| | Num==5) One { ASystem.out.println (num+ "Month:" + "Spring"); - } - Else if(num==6| | num==7| | Num==8) the { -System.out.println (num+ "Month:" + "Summer"); - } - Else if(num==9| | num==10| | num==11) + { -System.out.println (num+ "Month:" + "Autumn"); + } A Else if(num==1| | num==2| | Num==12) at { -System.out.println (num+ "Month:" + "Winter"); - } - Else - { -System.out.println ("Value out of range.")); in } - to } +}
View Code
1 classSwitchdemo2 {3 Public Static voidMain (String args[])4 {5 intA = 2;6 Switch(a)//expressions can only be of these four types: Byte,int,short,char7 {8 //Default:9 //System.out.println ("AAAA"); The default can be placed first, but it is still the last execution.Ten Case1: OneSystem.out.println ("a"); A Break; - Case2: -System.out.println ("B"); the Break; - Case3: -System.out.println ("C"); - Break; + Case4: -System.out.println ("D"); + default: ASystem.out.println ("Over"); at Break;//can be omitted. - } - } -}
View Code
1 /*2 Requirements: Write the month of the user input with switch and print out the season and month.3 */4 classswitchtest5{ Public Static voidMain (String args[])6 {7 intnum = 1;8 Switch(num)9 {Ten Case3: One Case4: A Case5: -System.out.println (num+ "Month:" + "Spring"); - Break; the Case6: - Case7: - Case8: -System.out.println (num+ "Month:" + "Summer"); + Break; - Case9: + Case10: A Case11: atSystem.out.println (num+ "Month:" + "Autumn"); - Break; - Case12: - Case1: - Case2: -System.out.println (num+ "Month:" + "Winter"); in Break; - default: toSystem.out.println ("Month out of range.")); + } - } the}
View Code
Java Basic Learning Note 2