▪ 需求说明: – 输入旧的用户名和密码,如果正确,方有权限更新 – 从键盘获取新的密码,进行更新
▪ 实现思路: – 1、创建管理员类的对象 – 2、利用while实现循环执行
import java.util.Scanner; public class Guanliyuan { String account="Aholic"; String password="147"; public void accountInfo(){ System.out.println("用户名:"+account+"\t密码:"+password); } public static void main(String[] args) { Guanliyuan Aholic=new Guanliyuan(); System.out.println("未修改之前的信息....."); Aholic.accountInfo(); Scanner sc=new Scanner(System.in); while(true){ System.out.println("请输入用户名:"); String accountName=sc.next(); System.out.println("请输入密码:"); String pwd=sc.next(); if(accountName.equals(Aholic.account)&&pwd.equals(Aholic.password)){ System.out.println("请输入新密码:"); pwd=sc.next(); Aholic.password=pwd; break; }else{ System.out.println("你输入的信息有误,请重新输入"); } } System.out.println("修改密码之后的账户信息------"); Aholic.accountInfo(); } }