if...else if 語法
if(條件式一) {
...
}
else if(條件式二) {
...
}
else {
...
}
繼續昨天的練習,把成績進行分類
package com.sea.java8;
public class IfTest3 {
public static void main(String[] args) {
double rand = Math.random(); //0.0 <= score < 1.0
// 0 - 100 => int
int scoreInt = (int)(rand *101 );
System.out.printf("Score = %d\n", scoreInt);
// 90+ => A; 80+ => B; 70+ => C; 60+ => D; 60- => E
if (scoreInt >=90) {
System.out.println("A");
scoreInt = 59; //不會在去執行其他道敘述句
}else if (scoreInt >= 80) {
System.out.println("B");
}else if (scoreInt >= 70) {
System.out.println("C");
}else if (scoreInt >= 60) {
System.out.println("D");
}else {
System.out.println("E");
}
}
}