我遇到的问题是我无法让我的密码验证程序检查一个字符串,以确保其中一个字符为大写,一个字符为小写,它将检查整个字符串中的一个其他并根据它正在检查的语句打印错误消息.
我查看了这个网站和互联网的答案,我无法找到一个.这是功课.
以下是我目前的代码.
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 …
Run Code Online (Sandbox Code Playgroud) 我想要这样的验证,My String必须至少包含一个字母.
我使用以下内容:
String s = "111a11";
boolean flag = s.matches("%[a-zA-Z]%");
Run Code Online (Sandbox Code Playgroud)
false
即使a
在我的字符串中,flag 也会给我s