Last active
January 16, 2018 14:06
-
-
Save dev-jonghoonpark/0b244e111f749b6e37e5c73ebeab4265 to your computer and use it in GitHub Desktop.
비전공자를 위한 코딩교육 2주차 : 조건문과 반복문을 이용한 로그인 시스템 Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Example { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
String pw; | |
boolean loginFailed; | |
int failCount = 0; | |
// do ... while 의 경우 먼저 1번 실행하고 조건문을 확인합니다. | |
do { | |
System.out.println("pw를 입력해주세요."); | |
pw = scanner.nextLine(); | |
loginFailed = !pw.equals("1234567890"); | |
if (loginFailed) { | |
failCount++; | |
System.out.println(failCount + "번 로그인에 실패하였습니다."); | |
} else { | |
System.out.println("로그인에 성공하였습니다."); | |
} | |
} while (loginFailed && failCount < 3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment