public class Test {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
sc.next();
String x=sc.next();
//想将用户名x改成手动输入,一运行就卡主,不知道哪里出了问题?去掉Scanner方法,直接给x赋值则运行正常
User u = new User(x, "123456");
User u1 = new User("Mike", "123456");
u.yhxx();
u1.yhxx();
System.out.println("===========================");
UserManager um = new UserManager();
um.checkUser(u, u1);
}
}
public class User {
private String user;
private String password;
public void yhxx() {
System.out.println("用户名:" + getUser());
System.out.println("密码:" + getPassword());
}
public User(String user, String password) {
this.user = user;
this.password = password;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
public class UserManager {
public String checkUser(User u, User u1) {
if (u.getUser() != null && u1.getPassword() != null) {
if (u.getUser().equals(u1.getUser())) {
System.out.println("用户名一致");
} else {
System.out.println("用户名不一致");
}
} else {
System.out.println("用户名输入为空");
}
return null;
}
}public class Test { public static void main(String[] args) { Scanner sc=new Scanner(System.in); sc.next(); String x=sc.next(); //想将用户名x改成手动输入,一运行就卡主,不知道哪里出了问题?去掉Scanner方法,直接给x赋值则运行正常 User u = new User(x, "123456"); User u1 = new User("Mike", "123456"); u.yhxx(); u1.yhxx(); System.out.println("==========================="); UserManager um = new UserManager(); um.checkUser(u, u1); }}
添加回答
举报
0/150
提交
取消