基本上这是我想要实现的行动:
Please type your new password:
1234
Please enter your password:
1234
This password is correct.
(And Vice Versa)
每次我启动或编辑此代码时,我得到的都是“此密码不正确” P.S:我对这一切都不熟悉! 这是我的主要课程:
package PasswordValidation;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner kbrdIn = new Scanner(System.in);
PasswordDB pwdObject = new PasswordDB();
System.out.println("Please type your new password: ");
String userPwd;
userPwd = kbrdIn.nextLine();
pwdObject.setPwd(userPwd);
pwdObject.checkPwd();
kbrdIn.close();
}
}
这是我的PasswordDB.java类:
package PasswordValidation;
import java.util.Scanner;
class PasswordDB {
Scanner pwdInput = new Scanner(System.in);
private String passWord;
public void setPwd(String name){
passWord = name;
}
public String getPwd(){
return passWord;
}
public final void checkPwd(){
System.out.println("Please enter the password: ");
String pwdIn = pwdInput.nextLine();
if(pwdIn == passWord){
System.out.println("Your password is correct.");
}else{
System.out.println("Your password is incorrect.");
}
}
}
答案 0 :(得分:0)
在Java中,您应该从不使用 cc -O3 -fexceptions -fPIC -DNBLAS -LD:/SuiteSparseBuild/UMFPACK/Lib -lsuitesparseconfig -lrt -I../Include -I../../AMD/Include -I../../SuiteSparse_config -c -DBUILD_DLL umfsolver.c
cc1: warning: fPIC ignored for target (all code is position independent)
cc -O3 -fexceptions -fPIC -DNBLAS -LD:/SuiteSparseBuild/UMFPACK/Lib -lsuitesparseconfig -lrt -I../Include -I../../AMD/Include -I../../SuiteSparse_config -shared -o umfsolver.dll umfsolver.o ../Lib/libumfpack.a ../../AMD/Lib/libamd.a ../../SuiteSparse_config/libsuitesparseconfig.a ../../CHOLMOD/Lib/libcholmod.a ../../COLAMD/Lib/libcolamd.a ../../metis-4.0/libmetis.a ../../CCOLAMD/Lib/libccolamd.a ../../CAMD/Lib/libcamd.a -lm -lrt ../../CHOLMOD/Lib/libcholmod.a ../../COLAMD/Lib/libcolamd.a ../../metis-4.0/libmetis.a ../../CCOLAMD/Lib/libccolamd.a ../../CAMD/Lib/libcamd.a -Wl,--add-stdcall-alias
来检查字符串是否相等。即使String对象包含相同的值,也认为它们不相等。这是因为Java通常处理对象的方式。
幸运的是,Java有一个内置的方法。 ==