【发布时间】:2009-11-13 15:40:44
【问题描述】:
我有一个简单的问题:
xyz 公司的密码应该是 6 个字符长,由字母和数字组合而成。编写一个程序片段来读入一个字符串并打印出一条消息,说明输入的字符串是否会被视为有效密码。
我需要帮助来完成此代码。我有这个无法使用 Java 代码的伪代码:
print "enter new password"
input newPassword
digitCounter =0
letterCounter = 0
for I = 0 to newPassword.length() by 1
c = newPassword.charAt(i)
if c is a digit
increment digitCounter
else if c is a letter
increment letterCounter
endif
endFor
if newPassword.length() >= 6 and digitCounter > 0 and letterCounter > 0
print "the password is valid"
else
print " password rejected, must be at least 6 characters long and be a mix of letters and digits "
endif
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++
到目前为止,我所拥有的只是 Java 代码:
import java.util.Scanner;
public class Password
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String thePassword;
int len, i, letterCounter = 0, digitCounter = 0;
char c;
Len = thePassword.length();
System.out.print("Enter the password: ");
thePassword = in.nextLine();
for (i = 0,i = len, )
{
c = in.charAt(1);
if ()
}
}
}
【问题讨论】:
-
如果这是作业,请添加“作业”标签。
-
我看到你的伪代码,还以为是Python……我很困惑,因为标题说的是Java!