java的创建管理员对象_java--更改管理员密码,请列位帮忙看看有没有更好的实现方式...
需求說明:輸入舊的用戶名和密碼,如果正確,方有權(quán)限更新,從鍵盤獲取新密碼,進(jìn)行更新
實(shí)現(xiàn)思路:1、創(chuàng)建管理員類的對(duì)象;2、利用while實(shí)現(xiàn)循環(huán)執(zhí)行
import?java.util.Scanner;
public?class?ChangePassword?{
public?String?name;
public?int?passwd;
public?static?void?main(String[]?args)?{
boolean?f?=?false;
Scanner?input?=?new?Scanner(System.in);
ChangePassword?cg?=?new?ChangePassword();
cg.name?=?"admin1";
cg.passwd?=?111111;
while?(!f)?{
System.out.println("請(qǐng)輸入用戶名:");
String?name?=?input.next();
System.out.println("請(qǐng)輸入密碼:");
int?passwd?=?input.nextInt();
if?(name.equals("admin1")?&&?passwd?==?111111)?{
f?=?true;
break;
}?else?{
System.out.println("用戶名和密碼不匹配!您沒有權(quán)限更新管理員信息");
break;
}
}
if?(f?==?true)?{
System.out.println("請(qǐng)輸入新密碼:");
int?passwd1?=?input.nextInt();
System.out.println("請(qǐng)?jiān)俅屋斎朊艽a:");
int?passwd2?=?input.nextInt();
while?(f?==?true)?{
if?(passwd1?==?passwd2)?{
System.out.println("修改密碼成功,您的新密碼是:"?+?passwd2);
f?=?false;
break;
}?else?{
System.out.println("您兩次輸入的密碼不一致,請(qǐng)重新輸入");
passwd2?=?input.nextInt();
}
}
}
}
}
總結(jié)
以上是生活随笔為你收集整理的java的创建管理员对象_java--更改管理员密码,请列位帮忙看看有没有更好的实现方式...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中单例模式是什么_pytho
- 下一篇: node工程默认url_node 爬虫入