package p01;
import java.util.Scanner;
public class Elevator {
public static void main(String[] args) {
int floor = 1;//目前電梯所在樓層
System.out.println("目前電梯在" + floor + "樓");
System.out.println("-------------------");
//Scanner 掃瞄器
//System.in 鍵盤
//new 建立物件
while (true) {//while迴圈 循環起點
System.out.println("1. 向上");
System.out.println("2. 向下");
System.out.println("3. 結束");
System.out.print("> ");
Scanner sc = new Scanner(System.in);//宣告掃瞄器變數 sc=掃描器的資料來源為鍵盤
//整數變數 menu 儲存從鍵盤輸入的值
int menu = sc.nextInt(); // nextInt() 掃瞄器從鍵盤讀取整數(會等待使用者輸入資料)
System.out.println("你的選擇是: " + menu);
System.out.println("-----------------");
if (menu == 1) { //如果menu等於 1
floor += 1;//floor 加1
} else if (menu == 2) {//如果menu等於2
floor -= 1;//floor減1
} else if (menu == 3) {//如果menu等於3,跳出迴圈
break;
}
System.out.println(floor + "樓到了");
}//迴圈結束
System.out.println("程式結束");
}
}