close

package p01;

import java.util.Scanner;

public class Elevator02 {

    public static void main(String[] args) {
        int floor = 1;//目前電梯所在樓層
        while (true) {

            System.out.println("目前電梯在" + floor + "樓");
            System.out.println("-------------------");

            //Scanner 掃瞄器
            //System.in 鍵盤
            //new 建立物件
            System.out.println("請輸入樓層(輸入0為結束)");
            System.out.print("> ");
            Scanner sc = new Scanner(System.in);//宣告掃瞄器變數 sc=拗描器的資料來源為鍵盤
            //整數變數 menu 儲存從鍵盤輸入的值
            int menu = sc.nextInt();   // nextInt() 掃瞄器從鍵盤讀取整數(會等待使用者輸入資料)
            if (menu >= 1) {
                floor = menu;
                System.out.println("你的選擇是: " + menu);
                System.out.println("-----------------");
                System.out.println(floor + "樓到了");

            } else if (menu <= 0) {
                break;

            }
        }

        System.out.println("程式結束");
    }

}

arrow
arrow
    文章標籤
    程式語言 HomeWork
    全站熱搜

    蛋餅Brook 發表在 痞客邦 留言(0) 人氣()