0

I got a problem in a program I'm working on here:

        String[ ][ ] applicant = new String[appno][2];

        for (i = 0; i < applicant.length; i++){
            System.out.println("Input applicant's name: ");
            appname = keyboard.nextLine();
            applicant[i][0] = appname;
            System.out.println("Input applicant's position: ");
            apppos = keyboard.nextLine();
            applicant[i][1] = apppos;
        }

The input works, but the code seems to skip the first instance of "appname = keyboard.nextLine()" every time (all further instances allow me to input). How do I solve this?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by NormR1
0

There may be some data in the keyboard buffer that has not been consumed when the loop is called. You might try flushing the input buffer first. What version of Java are you using? Also, what is the actual class you are using for keyboard input. There is no keyboard class per-se in current Java implementations as far as I know.

Edited by rubberman

0

Print out the contents of appname after it is read into to see if an empty String has been read. Be sure to put delimiters around appname when you print it so you can see if it is empty:
(">"+appname+"<").

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.