--Der Reihe nach
--Ast
- if
, switch
--Wiederholen
- while
,for
if
switch
//wenn Syntax
int r=new java.util.Random().nextInt(2);
if (r<1){
System.out.println("This is true by 'if'.");
}else{
System.out.println("This is false by 'if'.");
}
//Syntax wechseln
int s=new java.util.Random().nextInt(3);
switch(s){
case 0:
System.out.println("This is Case.0 by 'switch'.");
break;
case 1:
System.out.println("This is Case.1 by 'switch'.");
break;
case 2:
System.out.println("This is Case.2 by 'switch'.");
break;
default:
System.out.println("This is default by 'switch'.");
}
while
do while
for
//während Syntax
int w=1;
while(w<4){
System.out.println("Count No."+w+" by 'while'.");
w++;
}
//tun während der Syntax
int dw=3;
do{
System.out.println("Count No."+dw+" by 'do while'.");
dw--;
System.out.println("Count decrease -1 by 'do while'.");
}while(dw>0);
//für die Syntax
for(int i=1; i<=3; i++){
System.out.println("Count No."+i+" by 'for'.");
}
-- continue
: Setzen Sie die Schleife fort.
--break
: Brechen Sie aus der Schleife aus.
//Wiederholte Unterbrechung
for(int i=5; i>=1; i--){
if(i==3){
continue;
}
if(i==2){
break;
}
System.out.println("Count No."+i+" by 'for/continue(3)/break(2)'.");
}
[Einführung in Java 2nd Edition] (https://www.amazon.co.jp/dp/B00MIM1KFC/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1) Pp.098-133.