DAY 10
0
Mobile Development

# 判斷方式

## 1.if...else

### 範例(1)

output變成Yes，

output -> Yes

``````String season = "Spring";
String output = "";
if(season == "Spring"){
output = "Yes";
}
else{
output = "No";
}
``````

### 範例(2)

season是Spring -> output變成3~5月
season是Summer -> output變成6~8月
season是Fall -> output變成9~11月
season以上皆非 -> output變成12~2月

output -> 3~5月

``````String season = "Spring";
String output = "";
if(season == "Spring"){
output = "3~5月";
}
else if(season == "Summer"){
output = "6~8月";
}
else if(season == "Fall"){
output = "9~11月";
}
else{
output = "12~2月";
}
``````

## 2.switch...case

season是Spring -> output變成3~5月
season是Summer -> output變成6~8月
season是Fall -> output變成9~11月
season以上皆非 -> output變成12~2月

output -> 3~5月

``````String season = "Spring";
String output = "";
switch (season){
case "Spring":
output = "3~5月";
break;
case "Summer":
output = "6~8月";
break;
case "Fall":
output = "9~11月";
break;
default :
output = "12~2月";
break;
}
``````

# 迴圈方式

## 1.for

### 範例(1)

number.get(0) -> 0
number.get(1) -> 1
number.get(2) -> 2
number.get(3) -> 3
number.get(4) -> 4
number.get(5) -> 5
number.get(6) -> 6
number.get(7) -> 7
number.get(8) -> 8
number.get(9) -> 9
number.get(10) -> 10

``````ArrayList<Integer> number = new ArrayList<>();
//Step01:將0~10放入number(ArrayList)裡
//新建一個變數i，i每次回圈+1(i++)，直到i<=10
for (int i=0;i<=10;i++)
{
}
//Step02:獲得number(ArrayList)所有值(輸出來證明有無成功)
for (int j=0;j<=10;j++){
number.get(j);
}
``````

### 範例(2)-foreach

number.get(0) -> 0
number.get(1) -> 1
number.get(2) -> 2
number.get(3) -> 3
number.get(4) -> 4
number.get(5) -> 5
number.get(6) -> 6
number.get(7) -> 7
number.get(8) -> 8
number.get(9) -> 9
number.get(10) -> 10

``````ArrayList<Integer> number = new ArrayList<>();
//Step01:將0~10放入number(ArrayList)裡
//新建一個變數i，i每次回圈+1(i++)，直到i<=10
for (int i=0;i<=10;i++)
{
}
//Step02:獲得number(ArrayList)所有值(輸出來證明有無成功)
for (Integer j:number){
number.get(j);
}
``````

## 2.do...while...

number.get(0) -> 0
number.get(1) -> 1
number.get(2) -> 2
number.get(3) -> 3
number.get(4) -> 4
number.get(5) -> 5
number.get(6) -> 6
number.get(7) -> 7
number.get(8) -> 8
number.get(9) -> 9
number.get(10) -> 10

``````ArrayList<Integer> number = new ArrayList<>();
//新建一個變數count，count每次回圈+1，直到count<=10
Integer count = 0;
do{
count += 1;
}
while(count <= 10);
//這邊我使用同一個變數count，所以要先歸零才能重新使用
count = 0;
do{
number.get(count);
count += 1;
}
while(count <= 10);
``````