請輸入0~100,來決定您是否及格。
Single if/else example
import java.util.Scanner; public class If_Else { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please enter your score:"); int score = sc.nextInt(); sc.close(); // 單一 if/else 條件敘述來判斷成績是否及格 if (60<=score && score<=100) { System.out.print("Pass!!"); }else { System.out.print("failed!!"); } } }
條件運算式
conditional expressions