java初学,很简单的一个登录程序。
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)
就是看不出哪里错了。。。。
2楼说得对