200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 检查大写字母 java_在Java中检查字符串中的字母大小写(大写/小写)

检查大写字母 java_在Java中检查字符串中的字母大小写(大写/小写)

时间:2019-12-24 00:52:24

相关推荐

检查大写字母 java_在Java中检查字符串中的字母大小写(大写/小写)

我遇到的问题是我无法让我的密码验证程序来检查字符串,以确保其中的一个字符为大写字母,而一个字符为小写字母,它将检查整个字符串中是否存在一个字符。其他,并根据要检查的语句打印错误消息。

我已经查看了该站点和Internet上的答案,但是找不到。这是功课。

下面是我当前的代码。

import java.util.Scanner;

public class password

{

public static void main(String[] args)

{

Scanner stdIn = new Scanner(System.in);

String password;

String cont = "y";

char ch;

boolean upper = false;

boolean lower = false;

System.out.println("Setting up your password is easy. To view requirements enter Help.");

System.out.print("Enter password or help: ");

password = stdIn.next();

ch = password.charAt(0);

while (cont.equalsIgnoreCase("y"))

{

while (password.isEmpty())

{

System.out.print("Enter password or help: ");

password = stdIn.next();

}

if (password.equalsIgnoreCase("help"))

{

System.out.println("Password must meet these requirements." +

"\nMust contain 8 characters.\nMust contain 1 lower case letter." +

"\nMust contain 1 upper case letter.\nMust contain 1 numeric digit." +

"\nMust contain 1 special character !@#$%^&*\nDoes not contain the word AND or NOT.");

password = "";

}

else if (password.length() < 8)

{

System.out.println("Invalid password - Must contain 8 charaters.");

password = "";

}

else if (!(Character.isLowerCase(ch)))

{

for (int i=1; i

{

ch = password.charAt(i);

if (!Character.isLowerCase(ch))

{

System.out.println("Invalid password - Must have a Lower Case character.");

password = "";

}

}

}

else if (!(Character.isUpperCase(ch)))

{

for (int i=0; i

{

ch = password.charAt(i);

if (!Character.isUpperCase(ch))

{

System.out.println("Invalid password - Must have an Upper Case character.");

password = "";

}

}

}

else

{

System.out.println("Your password is " + password);

System.out.print("Would you like to change your password? Y/N: ");

cont = stdIn.next();

password = "";

}

while (!cont.equalsIgnoreCase("y") && !cont.equalsIgnoreCase("n"))

{

System.out.print("Invalid Answer. Please enter Y or N: ");

cont = stdIn.next();

}

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。