PAT (Basic Level) 1081 检查密码 (15分)JAVA解法

在这里插入图片描述

输入样例:

5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6

输出样例:

Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.


import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		input.nextLine();
		for (int i = 0; i < n; i++) {
			boolean neednum = true, needletter = true, luan = false;
			String password = input.nextLine();
			if (password.length() < 6) {
				System.out.println("Your password is tai duan le.");
				continue;
			} else {
				for (int j = 0; j < password.length(); j++) {
					if (!Character.isLetterOrDigit(password.charAt(j)) && password.charAt(j) != '.') {
						luan = true;
						break;
					} else if (Character.isDigit(password.charAt(j))) {
						neednum = false;
					} else if (Character.isLetter(password.charAt(j))) {
						needletter = false;
					}
 
				}
				if (luan) {
					System.out.println("Your password is tai luan le.");
					continue;
 
				} else if (neednum) {
					System.out.println("Your password needs shu zi.");
					continue;
				} else if (needletter) {
					System.out.println("Your password needs zi mu.");
					continue;
				} else {
				}
				System.out.println("Your password is wan mei.");
			}
 
		}
 
		input.close();
 
	}
 
}

在这里插入图片描述

发布了83 篇原创文章 · 获赞 1 · 访问量 1020

猜你喜欢

转载自blog.csdn.net/qq_44028719/article/details/103992806
今日推荐