java基础啊 通过编译了 但是输出时没任何结果 求助
public class userManager {public String checkUser(User one,User two) { String str=null; //判断用户名是否为空 if(one.getUserName().equals(two.getUserName())){ System.out.println("用户名为空"); } else if (!(one.getUserName().equals(two.getUserName()))) { //one.getUserName().equals(two.getUserName() //类似等价 System.out.println("用户名不一致"); } // 判断密码是否为空,是否一致 if(one.getPassword()==(two.getPassword())) { System.out.println("密码为空"); } else if(!(one.getPassword()==(two.getPassword()))){ System.out.println("密码不一致"); } return str;}}class User{ //定义属性用户名、密码 private String username; private int password; public String getUserName() { return username; } public void setUserName(String username) { this.username = username; } public int getPassword() { return password; } public void setPassword(int password) { this.password = password;} public void print() { System.out.println("用户名"+getUserName()); System.out.println("密码"+getPassword()); } }class Test{ // 测试方法 public static void main(String[] args) { //实例化对象,调用相关方法实现运行效果 User one=new User(); User two=new User(); one.setUserName("Lucy"); one.setPassword(123456); one.print(); two.setUserName("Mike"); two.setPassword(123456); two.print(); System.out.println("================="); userManager aaa=new userManager (); System.out.println(aaa.checkUser( one, two)); }} |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
看得有点乱,你把最后的System.out.println(aaa.checkUser( one, two));改成aaa.checkUser( one, two)试试 |
|
|
|
|
System.out.println(aaa.checkUser( one, two));
输出的返回值为str,而str值为空,故你就会觉得没有输出,你应该直接写aaa.checkUser( one, two) |
|
|
|
|