java中用数组怎么保存帐号和密码
代码如下importjava.util.Scanner;publicclassStudent{Users[]user=newUsers[10];Users[]user1=...
代码如下
import java.util.Scanner;
public class Student {
Users[] user = new Users[10];
Users[] user1 = new Users[10];
Scanner input = new Scanner(System.in);
String newPwd="",newId = "",newma="";
int i = 0;
//登录
public void login(){
user1[0] = new Users();
user1[0].Id = "张三";
user1[0].pwd = "123";
user[0] = new Users();
user[0].Id = "张三";
user[0].pwd = "123";
System.out.print("请输入用户名:");
newId = input.next();
System.out.print("请输入密码:");
newPwd = input.next();
for( i =0; i < user.length; i++){
if((user[i].Id).equals(newId) && (user[i].pwd).equals(newPwd)){
System.out.println("登录成功");
user1[i]=user[i];
change();
break;
}else{
System.out.println("登录失败");
}
}
}
public void change(){
System.out.print("请输入新密码:");
user1[i].pwd = input.next();
System.out.print("修改成功!");
System.out.print("新密码:" + user1[i].pwd);
login();
}
}
public class Test {
public static void main(String[] args) {
Student stu = new Student();
stu.login();
stu.change();
}
}
public class Users {
String Id;
String pwd;
} 展开
import java.util.Scanner;
public class Student {
Users[] user = new Users[10];
Users[] user1 = new Users[10];
Scanner input = new Scanner(System.in);
String newPwd="",newId = "",newma="";
int i = 0;
//登录
public void login(){
user1[0] = new Users();
user1[0].Id = "张三";
user1[0].pwd = "123";
user[0] = new Users();
user[0].Id = "张三";
user[0].pwd = "123";
System.out.print("请输入用户名:");
newId = input.next();
System.out.print("请输入密码:");
newPwd = input.next();
for( i =0; i < user.length; i++){
if((user[i].Id).equals(newId) && (user[i].pwd).equals(newPwd)){
System.out.println("登录成功");
user1[i]=user[i];
change();
break;
}else{
System.out.println("登录失败");
}
}
}
public void change(){
System.out.print("请输入新密码:");
user1[i].pwd = input.next();
System.out.print("修改成功!");
System.out.print("新密码:" + user1[i].pwd);
login();
}
}
public class Test {
public static void main(String[] args) {
Student stu = new Student();
stu.login();
stu.change();
}
}
public class Users {
String Id;
String pwd;
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2个回答
展开全部
String[] userNames = new String[] { "admin", "admin1" };// 保存用户名
String[] passWords = new String[] { "admin", "admin1" };// 保存密码
String[] passWords = new String[] { "admin", "admin1" };// 保存密码
追答
就这么zuo
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询