怎么让我的输入账号与用户名成为同一个变量
package test;public class Admin {
public static void main(String[] args) {
// TODO Auto-generated method stub
Register register = new Register();
register.show();
Login login = new Login();
login.show();
}
}
package test;
import java.util.Scanner;
public class Register {
String uname;
String pwd;
public void show()
{
Scanner input = new Scanner(System.in);
System.out.print("请注册用户名:");
this.uname = input.next();
System.out.print("请输入密码:");
this.pwd = input.next();
if (this.pwd.length() >= 6)
{
System.out.print("注册成功!");
}
else
{
System.out.print("用户名不能少于6位!");
}
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
package test;
import java.util.Scanner;
public class Login {
String uname;
String pwd;
public void show(){
Scanner input = new Scanner(System.in);
System.out.print("请输入用户名:");
uname = input.next();
System.out.print("请输入密码:");
pwd = input.next();
if (uname.equals("TOM")&& pwd.equals("1234567"))
{
System.out.print("登录成功!");
}
else
{
System.out.print("用户名或密码不匹配,登录失败!");
}
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}