问题描述:
解析:
import javax.swing.*
import java.awt.*
import java.awt.event.*
class C {
public static void main( String[] args ) {
JFrame f = new JFrame( )
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE )
f.setSize( 300, 140 )
f.setLocation( 250, 250 )
Container c = f.getContentPane( )
c.setLayout( new FlowLayout( ) )
JPasswordField
c.add( new JLabel( "Enter your password into this JPasswordField: " ) )
JPasswordField jpf = new JPasswordField( 10 )
jpf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd =
new String( ( ( JPasswordField ) e.getSource( ) ).getPassword( ) )
JOptionPane.showMessageDialog( null, "Your password is " + pwd )
}
}
)
c.add( jpf )
TextField
c.add( new JLabel( "Or enter your password into this TextField: " ) )
TextField tf = new TextField( 12 )
tf.setEchoChar( '缓仔搜*' )
tf.addActionListener(
new ActionListener( ) {
public void actionPerformed( ActionEvent e ) {
Object pwd = ( ( ( TextField ) e.getSource( ) ).getText( ) )
JOptionPane.showMessageDialog( null, "Your password is " + pwd )
}
}
)
c.add( tf )
f.setVisible( true )
}
}
public static void main(String[] args) {System.out.println("请输入局纤密码桐姿仿:")
Scanner scanner=new Scanner(System.in)
String password=scanner.nextLine()
System.out.println("你册梁输入的密码是:"+password)
scanner.close()
}
已完成,复制粘贴即可。import java.util.Scanner
public class YuGiOh
{
private static void checkPass ( String password )
{
String regp = ".*[A-Z].*"
String rego 做正御= ".*[a-z].*"
String regq = ".*\\d.*"
String regs = ".*[\\`\\-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\=\\[\\{\\}\\]\\\\:\\,\\.\\<\\>纯岩\\/\\?].*"
String regex = "^[a-zA-Z\\d\\`\\-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\=\\[\\{\\}\\]\\\\:\\,\\.\\<\\>\\/\\?]{6,}$"
String result = ""
if (password.length () < 6)
{
result += "\t\t-contain at least 清郑six characters. Your password is only " + password.length () + " characters long.\n"
}
if (!password.matches (regp))
{
result += "\t\t-contain at least one uppercase letter.\n"
}
if (!password.matches (rego))
{
result += "\t\t-contain at least one lowercase letter.\n"
}
if (!password.matches (regq))
{
result += "\t\t-contain at least one number.\n"
}
if (!password.matches (regs))
{
result += "\t\t-contain at least one of the following special characters: `!@#$%^&*()_+=[{}]:,.<>/?\n"
}
else if (!password.matches (regex))
{
result += "\t\t-not contain an invalid character. The valid special characters: `!@#$%^&*()_+=[{}]:,.<>/?\n"
}
if (!"".equals (result))
{
System.out.println ("Your password must:\n" + result)
}
else
{
System.out.println ("Your valid password is: " + password)
}
System.out.println ()
}
public static void main ( String[] args )
{
Scanner scanner = new Scanner (System.in)
while (true)
{
System.out.print ("Enter a valid password: ")
String password = scanner.nextLine ()
checkPass (password)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)