Java编程——实现会员注册,要求用户名长度不小于3,密码长度不小于6,注册时两次输入密码必须相同 (字符串)
package register; import java.util.Scanner; public class Register
{ String name; String password; String newPassword; public void nameExe()
{ Scanner input=new Scanner(System.in); System.out.println("请输入用户名,密码和验证密码"); System.out.print("用户名:"); name=input.next(); System.out.print("密码:"); password=input.next(); System.out.print("验证密码:"); newPassword=input.next(); while(name.length()<3||(password.equals(newPassword)==false)||(password.length()<6))
{ if(name.length()<3)
{ System.out.println("用户名不能小于3"); } if((password.equals(newPassword)==false)||password.length()<6)
{ System.out.println("两次输入密码不一样或密码不能小于6位"); } System.out.println("\n"+"请重新输入"); System.out.print("用户名:"); name=input.next(); System.out.print("密码:"); password=input.next(); System.out.print("验证密码:"); newPassword=input.next(); } System.out.println("注册成功!"); }
}
package register; public class Verify extends Register { public static void main(String[] args) { Verify m1=new Verify(); m1.nameExe(); } }