import java.util.Scanner;
import java.lang.*;
public class Register {
public static void main(String[] args){
Verify verify = new Verify("Admin","123456");
Scanner input = new Scanner(System.in);
String userName = "";
String passWord = "";
String newPassWord;
String confirmPassWord;
System.out.println("请输入登录账号: ");
userName=input.next();
System.out.println("请输入登录密码: ");
passWord=input.next();
if(userName.equals(verify.getUserName())&&passWord.equals(verify.getPassWord())){
System.out.println("congradulation to you")
}else {
System.out.println("Warning");
}
}
}
调用:
public class Verify {
String userName = "";
String passWord = "";
public Verify(String userName,String passWord){
this.userName=userName;
this.passWord=passWord;
}
public void getUserName(){
return userName;
}
public void getPassWord(){
return passWord;
}
}
结果:Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method equals(Object) in the type String is not applicable for the arguments (void)
The method equals(Object) in the type String is not applicable for the arguments (void)
Syntax error, insert ";" to complete BlockStatements
at Register.main(Register.java:20)
就是看不出哪里错了。。。。
------解决方案--------------------
你这两句能编译吗,亲?
public void getUserName(){
return userName;
}
public void getPassWord(){
return passWord;
}
返回值应该是String。
------解决方案--------------------
是的 一楼这两句是不能通过编译的
public String getUserName(){
return userName;
}
public String getPassWord(){
return passWord;
}
改成这样子就行啦
------解决方案--------------------
2楼说得对