【发布时间】:2011-02-03 22:20:27
【问题描述】:
我正在尝试用 Java 编写一个程序来检查三个特定的输入。它必须通过这些测试:
- 至少
7个字符。 - 同时包含
upper和lower大小写字母字符。 - 至少包含
1数字。
到目前为止,我已经能够检查是否有 7 个字符,但是最后两个字符有问题。我应该在循环中放入什么作为 if 语句来检查数字并使其大写和小写。任何帮助将不胜感激。 这是我目前所拥有的。
import java.awt.*;
import java.io.*;
import java.util.StringTokenizer;
public class passCheck
{
private static String getStrSys ()
{
String myInput = null; //Store the String that is read in from the command line
BufferedReader mySystem; //Buffer to store the input
mySystem = new BufferedReader (new InputStreamReader (System.in)); //creates a connection to system input
try
{
myInput = mySystem.readLine (); //reads in data from the console
myInput = myInput.trim ();
}
catch (IOException e) //check
{
System.out.println ("IOException: " + e);
return "";
}
return myInput; //return the integer to the main program
}
//****************************************
//main instructions go here
//****************************************
static public void main (String[] args)
{
String pass; //the words the user inputs
String temp = ""; //holds temp info
int stringLength; //length of string
boolean goodPass = false;
System.out.print ("Please enter a password: "); //ask for words
pass = getStrSys (); //get words from system
temp = pass.toLowerCase ();
stringLength = pass.length (); //find length of eveyrthing
while (goodPass == false)
{
if (stringLength < 7)
{
System.out.println ("Your password must consist of at least 7 characters");
System.out.print ("Please enter a password: "); //ask for words
pass = getStrSys ();
stringLength = pass.length ();
goodPass = false;
}
else if (/* something to check for digits */)
{
}
}
【问题讨论】:
标签: java string loops passwords