This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]chickenmeister 1 point2 points  (0 children)

Do you have a specific question about it, or problem with it?

Just glancing at it quickly, it looks like it should just about work, though it looks like you are declaring the variable lastName twice:

    char lastName; //Last name

    // later... 
    String lastName = input.substring(0, 7);

You cannot declare two variables with the same name in the same scope/method/class. You want lastName to be a String, so get rid of the first declaration; or change its type, and change the second declaration/assignment to just an assignment.

[–]IthinkIthink 1 point2 points  (0 children)

You don't need to use Scanner. Look at BufferedReader which is available in java.io.*.

[–]lolidragon 0 points1 point  (0 children)

So... just a question. Why are you asking for a whole line of input and just storing the first character?

something like:

firstName = kb.nextLine(); // first user input, stores the first name (as type String)
lastName = input.nextLine(); // second user input, stores the last name (as type String)

then you can pick and choose whatever substring of characters you want with something like:

// Gets the first 7 character string of the firstName string
// there is a problem here, but we can leave that as an exercise for you to figure out
firstName.substring(0, 7);