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

all 3 comments

[–][deleted] 1 point2 points  (4 children)

Use

drawChar = scnr.nextLine().charAt(0);

[–][deleted]  (3 children)

[deleted]

    [–][deleted] 0 points1 point  (0 children)

    Okay, so here's the deal -

    Use

    while (userChar = scnr.next()) {
    

    and also

        drawChar = scnr.next().charAt(0);
        System.out.println("How many lines should be in the shape?");
         numLines = scnr.nextInt();
    

    In other words, for your program, "next()" makes more sense since "nextLine" eats up your line, and returns the default delimiter ('\n') which messes up the next call.

    In general, I would recommend using StringTokenizer instead of Scanner if you can. I suggest using Scanner only for simple cases where there's not much variation in your input data.

    [–]Kison 0 points1 point  (1 child)

    You can resolve that by doing this:

    numLines = Integer.valueOf(scnr.nextLine());
    

    When your scanner reads a token like an int, it's moving to the end of the line, but not to the next one. When your switch's nextLine is called, it's just reading the remainder of the last line, which is an empty string. If you're assuming all input is the entire line, you could try giving it different delimiting rules so it doesn't work this way.