1 package demo3;
 2 
 3 import java.util.Scanner;
 4 
 5 //会员注册,用户名长度不小于3,密码长度不小于6,两次输入的密码必须相同
 6 public class Register {
 7     public static void main(String[] args) {
 8         Scanner input=new Scanner(System.in);
 9         do {
10             boolean isRight=false;
11             System.out.print("请输入用户名:");
12             String userName=input.next();
13             System.out.print("请输入密码:");
14             String pwd=input.next();
15             System.out.print("请再次输入密码:");
16             String nextPwd=input.next();
17             
18             if(userName.length()<3 || pwd.length()<6) {
19                 System.out.println("用户名长度不能小于3或密码长度不能小于6!");
20             }else {
21                 if(pwd.equals(nextPwd)) {
22                     System.out.println("注册成功!请牢记用户名和密码。");
23                     isRight=true;
24                 }else {
25                     System.out.println("两次输入的密码不相同!");
26                 }
27             }
28             if(isRight) {
29                 break;
30             }
31         }while(true);
32         
33     }
34 }

 

posted on 2018-12-12 13:52  从零开始-白  阅读(223)  评论(0编辑  收藏  举报