java 设置一个管理员类,修改用户密码

先创建一个管理员类

public class Administrator {
    String name;
    String password;// 密码

    public void show() {
        System.out.println("姓名" + name + "密码" + password);
    }

}

主函数

import java.util.Scanner;
public class ChangePassword {
    public static void main(String []args){
        String nameInput;
        String Pwd;
        String pwdConfirm;
        Scanner input=new Scanner(System.in);
        Administrator admin=new Administrator();
        admin.name="admin1";
        admin.password="123456";
        System.out.println("Please enter your name :
");
        nameInput=input.next();
        System.out.println("Please enter your password:
");
        Pwd=input.next();
        if(admin.name.equals(nameInput)&&admin.password.equals(Pwd)){
            System.out.println("Please enter new Pwd:
");
            Pwd=input.next();
            System.out.println("Please enter new Pwd again:
");
            pwdConfirm=input.next();
            while(!Pwd.equals(pwdConfirm))
            {
                System.out.println("Please enter new Pwd again:
");
                System.out.println("Please enter new Pwd:
");
                Pwd=input.next();
                System.out.println("Please enter new Pwd again:
");
                pwdConfirm=input.next();
            }
            System.out.println("SUCCESS, your new pwd is "+Pwd);
        System.out.println("用户名:"+admin.name+"密码:"+Pwd);
       
        
        }
        else{
            System.out.println("the usename is not match the pwd:
");
            
            
        }
        
    }
    
}
原文地址:https://www.cnblogs.com/Angella/p/6721400.html