※J.Y Chen 的個人部落格 ※

Just Follow Our Heart And We will shine!

49 瀏覽人次

【程式語言】JAVA的第四堂課 |偵測密碼對或錯 (if-else / while)

Published: in JAVA by .

import java.util.Scanner;
public class hw3_1 {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int input;
        int cnt = 0;
        int passwd = 6128;
        while (true) {
            System.out.print("please input the passwd:");
            input = scn.nextInt();
            if (input != passwd) {
                cnt += 1;
            }
            else if(input == passwd) {
                System.out.print("Correct!! Welcome to this system!");
                break;
            }
            if(cnt == 3 ) {
                System.out.print("You input over three times,bye!");
                break;
            }
        }
    } 
}
©2019 - 2024 Henry Chen