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

我所拥有的问题是我无法获得我的密码验证程序来检查字符串,以确保其中1个字符是大写字母,一个是小写字母,它将检查整个字符串中的一个,并打印基于哪个语句正在检查的错误消息。

我已经看过这个网站和互联网的答案,我无法找到一个。这是家庭作业

以下是我当前的代码。

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 = "";

}

// end if

} //end for

}

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 = "";

} // end if

} //end for

}

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();

}

}

} // end main

} // end class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值