怎样用java设置帐号和密码
1个回答
推荐于2018-05-13
展开全部
public class User{
//定义私有属性 用户名和密码
private String userName;
private String password;
public User(String userName,String password){
this.userName=userName;
this.password=password;
}
//私有属性的set get 方法
public void setUserName(String userName){
this.userName=userName;
}
public void setPassword(String password){
this.password=password;
}
public String getUserName(){
return this.userName;
}
public String getPassword(){
return this.password;
}
//用来判断用户名和密码是否正确
public boolean panDuan(){
if("用户名".equals(this.userName)&&"密码".equals(this.password)){
System.out.println("登入成功!");
return true;
}else{
System.out.println("登入失败!");
return false;
}
}
public static void main (String[] args){
System.out.println("请输入用户名:");
Scanner sc=new Scanner(System.in);
String userName=sc.nextLine();
System.out.println("请输入密码:");
String password=sc.nextLine();
User u=new User(userName,password);
u.panDuan();
}
}
//定义私有属性 用户名和密码
private String userName;
private String password;
public User(String userName,String password){
this.userName=userName;
this.password=password;
}
//私有属性的set get 方法
public void setUserName(String userName){
this.userName=userName;
}
public void setPassword(String password){
this.password=password;
}
public String getUserName(){
return this.userName;
}
public String getPassword(){
return this.password;
}
//用来判断用户名和密码是否正确
public boolean panDuan(){
if("用户名".equals(this.userName)&&"密码".equals(this.password)){
System.out.println("登入成功!");
return true;
}else{
System.out.println("登入失败!");
return false;
}
}
public static void main (String[] args){
System.out.println("请输入用户名:");
Scanner sc=new Scanner(System.in);
String userName=sc.nextLine();
System.out.println("请输入密码:");
String password=sc.nextLine();
User u=new User(userName,password);
u.panDuan();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询