package 更改管理员密码;
import java.util.Scanner;
public class Administrator {
String yhm;
String password;
int age;
String limit; //管理员权限
public void introduce(){
System.out.println("----------------------------");
System.out.println(“用户名:” +yhm + “\n年龄:” + age + “\n管理员权限:” + limit);
}
public void init(){
System.out.println("----------------------------");
Scanner sc = new Scanner(System.in);
System.out.print(“请输入用户名:”);
yhm = sc.next();
System.out.print(“请输入密码:”);
password = sc.next();
System.out.print(“请输入年龄:”);
age = sc.nextInt();
System.out.print(“请输入管理员权限:”);
limit = sc.next();
}
public void modify_password(){
System.out.println("-----------修改密码-----------");
String yhm1;
String password_m;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print(“请输入旧用户名:”);
yhm1=sc.next();
System.out.print(“请输入旧密码:”);
password_m = sc.next();
if(yhmyhm1&&password_mpassword){
System.out.print(“用户名与密码输入正确,请输入新密码:”);
password = sc.next();
System.out.println(“密码修改成功!”);
break;
}
System.out.println(“账户或密码输入错误,请重新输入!”);
}
}
package 更改管理员密码;
public class TestAdministrator {
public static void main(String[] args) {
Administrator adm1 = new Administrator();
adm1.init();
adm1.introduce();
adm1.modify_password();
}
}
大佬们帮着修改一下,此代码输入旧密码与旧用户名后,一直是死循环