๋ฌธ์
์ํธ์ ๊ธธ์ด๋ 10 ~ 30์ ์ฌ์ด
์ํธ์๋ ์ซ์, ์๋ฌธ์, ๋๋ฌธ์, ํน์ ๋ฌธ์๊ฐ ํฌํจ๋์ด์ผ ํจ
ํน์๋ฌธ์๋ (!, %, _, #, &, +, -, *, /)์ 9๊ฐ ์ค ํ๋
์ ๋ ฅ ๋ฐ์ ํจ์ค์๋๊ฐ ์กฐ๊ฑด์ ๋ง์กฑํ๋ฉด "Good password", ์๋๋ฉด "Bad password" ์ถ๋ ฅ ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํ๊ณ
์ฌ์ฉ์๊ฐ "์ข ๋ฃ" ๋๋ "exit" ์ ๋ ฅํ๋ฉด ํ๋ก๊ทธ๋จ ์ข ๋ฃ
* ๋ฐฐ์ด ๊ฒ์ ๋ณต์ตํ ๊ฒธ ์ ๊ท์์ ์ด์ฉํ์ง ์๊ณ ํ์์ต๋๋ค.
package ์ํธ์ฒดํฌ๋ฌธ์ ;
import java.util.Scanner;
public class Password {
String password;
public void setPassword() {
Scanner sc = new Scanner(System.in);
password = sc.next();
}
public boolean pwLength() {
if(password.length() >= 10 && password.length() <= 30) {
return true;
}
return false;
}
public boolean pwOptionSmallLetter() {
for(int i = 0; i < password.length(); i++) {
if(password.charAt(i) >= 'a' && password.charAt(i) <= 'z') return true;
}
return false;
}
public boolean pwOptionBigLetter() {
for(int i = 0; i < password.length(); i++) {
if(password.charAt(i) >= 'A' && password.charAt(i) <= 'Z') return true;
}
return false;
}
public boolean pwOptionNum() {
for(int i = 0; i < password.length(); i++) {
if(password.charAt(i) >= '0' && password.charAt(i) <= '9') return true;
}
return false;
}
public boolean pwOptionSpeChar() {
String specialLetter = "!%_&#+-*/";
for(int i = 0; i < specialLetter.length(); i++) {
for(int j = 0; j < password.length(); j++) {
if(specialLetter.charAt(i) == password.charAt(j)) return true;
}
}
return false;
}
public void getPassword() {
if(pwLength() && pwOptionSmallLetter() && pwOptionBigLetter() && pwOptionSpeChar() && pwOptionNum()) {
System.out.println("Good password");
}
else System.out.println("Bad password");
}
public void confirmPw() {
while(true) {
setPassword();
pwLength();
pwOptionSpeChar();
pwOptionNum();
pwOptionBigLetter();
pwOptionSmallLetter();
if(password.equals("์ข
๋ฃ") || password.equals("exit")) return;
getPassword();
}
}
}
package ์ํธ์ฒดํฌ๋ฌธ์ ;
public class PwdCheckMain {
public static void main(String[] args) {
Password password = new Password();
password.confirmPw();
}
}
'๐ Algorithm > etc' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ(Java) - 10์ง์ 2์ง์ ๋ณ๊ฒฝํ๊ธฐ (0) | 2023.02.06 |
---|---|
์๋ฐ(Java) - ์ซ์ ์ฐพ๊ธฐ (0) | 2023.01.19 |
์๋ฐ(Java) ํ์ ์ง์ ๋๋์ด ๋ด๊ธฐ (1) | 2023.01.12 |
์๋ฐ(Java) ์์ ํ๋ณํ๊ธฐ (0) | 2023.01.12 |
C์ธ์ด - ๋ณ ์ฐ๊ธฐ(์ฌ๊ฐํ, ์ ๋น ์ฌ๊ฐํ, ์ง๊ฐ ์ผ๊ฐํ, ์ญ ์ง๊ฐ์ผ๊ฐํ, ์ ์ผ๊ฐํ, ์ญ ์ ์ผ๊ฐํ, ์ ๋น ์ ์ผ๊ฐํ, ์ ๋น ์ญ ์ ์ผ๊ฐํ) (2) | 2023.01.08 |