import java.util.Scanner;
public class HomeExercise {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
String password;
boolean dig = false,blank=true;
System.out.print("Enter a password");
password = input.nextLine();
if(password.length()<6)
{
System.out.println("密码输入无效,密码至少为6位");
}
else
{
for(int i = 0;i<password.length();i++)
{
if(Character.isDigit(password.charAt(i)))
dig = true;
if(password.charAt(i)==' ') {
blank = false;
}
}
if(dig && blank)
{
System.out.println("密码输入有效,密码为:"+password);
}
else {
System.out.println("密码输入无效,密码至少包含一位数字且不能含有空格!");
}
}
}
}
编写一个程序,要求用户输入密码字符串。您的程序应该验证密码是否符合以下条件:1、密码至少有六个字符长 2、密码至少要有一个数字 3、密码字符串不能含有空格 测试后,显示一条消息,提示输入的密码是否有效
最新推荐文章于 2023-05-03 16:24:07 发布