【程式語言】JAVA的第四堂課 |偵測密碼對或錯 (if-else / while)
Published:
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;
}
}
}
}