使用来自用户的给定信息生成用户名

时间:2014-06-27 13:25:32

标签: java

嗨,我可以有人帮助我完成我的课程吗? 我的教授要求我们做一个程序,从用户那里获取信息并从用户的姓氏和名字生成一个6个字母的用户名。 用户名的前3个字母是firstname的前3个字母,另外3个是用户姓氏的最后3个字母。我们需要通过登录模块进行测试 测试用户名和密码是否与生成的用户名和用户输入的密码相匹配

就我而言,我无法找到答案,而我们的教授并没有告诉我们这一点,而且我现在正在努力。

这是我现在的程序>>>

public static InputStreamReader r = new InputStreamReader(System.in);
public static BufferedReader i = new BufferedReader(r);

public static void main(String[]args) throws Exception{

    String Lname,Fname,Mi;
    int age,bday;
    float pass;

    System.out.print("Enter Last Name: ");
    Lname=i.readLine();
    System.out.print("Enter First Name: ");
    Fname=i.readLine();
    System.out.print("Enter Middle Name: ");
    Mi=i.readLine();
    System.out.print("Age: ");
    age=Integer.parseInt(i.readLine());
    System.out.print("Birthday (MM/DD/YY) :");
    bday=Integer.parseInt(i.readLine());
    System.out.println("Password Must Be A 4-6 Digit Combination");
    System.out.print("Enter Password : ");
    pass=Float.parseFloat(i.readLine());

    System.out.println("Please Wait While Generating Your UserName");
    for(int j=0;j<=35;j++)
    {
            try{
                Thread.sleep(100);
            }
            catch(InterruptedException ex)
            {
                //do nothing
            }
            System.out.print("*");
    }


}

有人可以帮我吗....

1 个答案:

答案 0 :(得分:0)

你可以:

String username = FName.substring(0,3) + LName.substring(LName.length() - 3, LName.length());

您应该检查FName和LName的最小长度是3个字符,否则您将获得异常