One: Data type
Base type, string type, and null type can specify a direct amount
Two: Conditional statements
If
If-else
Switch
No matches, execution by item
PackageOne ; Public classSWITCHS1 { Public Static voidMain (string[] args) {intx= 0; Switch(x) {default: System.out.println ("Default"); Case1: System.out.println (1); Case2: System.out.println (2); } }}
Start execution from a match
PackageOne ; Public classSWITCHS2 { Public Static voidMain (string[] args) {intx= 0; Switch(x) {default: System.out.println ("Default"); Case0: System.out.println (0); Case1: System.out.println (1); Case2: System.out.println (2); } }}
PackageOne ; Public classSWITCHS2 { Public Static voidMain (string[] args) {intx= 0; Switch(x) { Case0: System.out.println (0); Case1: System.out.println (1); Case2: System.out.println (2); default: System.out.println ("Default"); } }}
Three: Circular statements
For
While
Do-while
PackageOne ; Public classXunhuan { Public Static voidMain (string[] args) { for(intA = 0; A < 10; a++) {System.out.print (a); } System.out.println (); intx = 0; while(X < 20) {System.out.print (x); X++; } System.out.println (); inty = 0; Do{System.out.print (y); Y++; } while(Y < 10); }}
Four: Jump statements
Break (jump out of the loop)
Continue (enter next cycle)
Package One ; Public class Tiaozhuan { publicstaticvoid main (string[] args) { for (int a = 0; a <; a++) { System.out.print (a); if (a% 2 = = 0) {continue; } System.out.println ("$"); }}}
Basic syntax for Java