实现会员注册,注册的用户名长度不能小于三,密码长度不能小于六
给的提示是:1.创建类register 2.创建方法verify(),用来验证用户名和密码的信息 用类和对象做 求代码
import java.util.Scanner;
public class Register
{
private String username;
private String password;
public Register ( String username, String password )
{
this.username = username;
this.password = password;
}
public boolean verfiy ()
{
return username.length () >= 3 && password.length () >= 6;
}
public static void main ( String[] args )
{
Scanner scanner = new Scanner (System.in);
System.out.println ("输入用户名:");
String username = scanner.nextLine ();
System.out.println ("输入密码:");
String password = scanner.nextLine ();
scanner.close ();
Register register = new Register (username, password);
if (register.verfiy ())
{
System.out.println ("合法");
}
else
{
System.out.println ("非法");
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-07-06
伪登录,
import java.util.Scanner;
public class Loregister{
/**
* @param args
*/
public static void main(String[] args) {
register l=new register();
String reg=l.to();
System.out.println(reg);
}
public String to(){
Scanner input=new Scanner(System.in);
System.out.println("请输入用户名");
String name=input.next();
System.out.println("请输入密码");
String pass=input.next();
System.out.println("请确认密码");
String repass=input.next();
if(name.length()<3){
return "账号长度不能小于3位";
}
if(pass.length()<8){
return "密码长度不能小于8位";
}
if(!pass.equals(repass)){
return "两次密码不同";
}
else {
return "注册成功,账号是"+name+"密码"+pass;
}
}
}
import java.util.Scanner;
public class Loregister{
/**
* @param args
*/
public static void main(String[] args) {
register l=new register();
String reg=l.to();
System.out.println(reg);
}
public String to(){
Scanner input=new Scanner(System.in);
System.out.println("请输入用户名");
String name=input.next();
System.out.println("请输入密码");
String pass=input.next();
System.out.println("请确认密码");
String repass=input.next();
if(name.length()<3){
return "账号长度不能小于3位";
}
if(pass.length()<8){
return "密码长度不能小于8位";
}
if(!pass.equals(repass)){
return "两次密码不同";
}
else {
return "注册成功,账号是"+name+"密码"+pass;
}
}
}