package one;public class User { private String name; private String password; public User(String name,String password) { this.name = name; this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public void print() { System.out.println("用户名:"+name); System.out.println("密码:"+password); } }分割线------------------------------------------------------------------------------------------------------------package one;//管理类public class UserManager { public void check(User one ,User two) { if(one.getName()==two.getName()) { System.out.println(" "); } if(one.getName()!=two.getName()) { System.out.println("用户名不一致!"); } if(one.getPassword()==two.getPassword()) { System.out.println(" "); } if(one.getPassword()!=two.getPassword()) { System.out.println("密码不一致!"); } } }//为什么无法判断 (提问)//私有变量使用简化 (回顾)//简化主方法代码 (进化)分割线------------------------------------------------------------------------------------------------------------package one;public class Test { public static void main(String[] args) { User one = new User("花花","123456"); User two = new User("凡凡","123456"); one.print(); two.print(); System.out.println("==============="); UserManager n = new UserManager(); n.check(one, two); //System.out.println(); }}效果图用户名:花花密码:123456用户名:凡凡密码:123456===============用户名不一致!
添加回答
举报
0/150
提交
取消