需求说明
模拟实现用户密码管理:输入旧的用户名和密码,如果正确,方有权限更新;从键盘获取新的密码,进行更新。
思路:首先写一个原始密码的类
复制代码
1
2
3
4
5
6
7
8
9
10
11
12import java.util.Scanner; public class Administrator { String name = "张三"; String pssword = "123456"; public void changePsssword(){ Scanner input = new Scanner(System.in); System.out.println("密码正确,请输入新密码"); pssword = input.next(); System.out.println("密码修改成功"); } }
然后写新密码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import java.util.Scanner; public class Newpassword { public static void main(String[] args) { Scanner input = new Scanner(System.in); Administrator newpassword = new Administrator(); System.out.println("请输入用户名:"); String name = input.next(); System.out.println("请输入原始密码:"); String pssword = input.next(); if(newpassword.name.equals(name)&&newpassword.pssword.equals(pssword)){ newpassword.changePsssword(); }else{ System.out.println("用户或密码输入错误,不能修改"); } } }
最后
以上就是贪玩冰淇淋最近收集整理的关于JAVA类和对象简单练习之用户密码管理的全部内容,更多相关JAVA类和对象简单练习之用户密码管理内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复