问题遇到的现象和发生背景 :输入什么都显示用户名错误
我想要达到的目的: 编写程序,模拟用户登录功能,程序开始运行时先在 DOS 命令窗口中初始化登录页
//面,提醒用户输入用户名和密码,当用户输入用户名为 admin,密码为 123 的时候登录成功,
//打印欢迎信息,当用户输入的用户名和密码不正确打印错误提示信息并退出系统。对于以上的
//程序大家尽可能定义相关方法来完成,不要将所有代码都放到 main 方法当中。
import java.util.Scanner;
public class diGui {
public static void main(String[] args) {
System.out.print("请输入用户名:");
Scanner sc=new Scanner(System.in);
if(enter(sc.next())){
System.out.print("请输入密码:");
Scanner cs=new Scanner(System.in);
if(enter2(cs.nextInt())){
System.out.print("登入成功,欢迎!");
}else{
System.out.print("密码错误,请重试!");}
}else{
System.out.println("用户名错误");}
}
public static boolean enter(String x){
while (x=="admin"){
return true;
}return false;
}
public static boolean enter2(int b){
while (b==123){
return true;
}return false;
}
}