Why is first for loop iteration skipped?

后端 未结 5 2163
粉色の甜心
粉色の甜心 2021-01-26 10:57

my code is yielding an unexpected result. It seems my for loop skips the first iteration and I don\'t understand why.

public static void main(String[] args) {

         


        
5条回答
  •  执念已碎
    2021-01-26 11:32

    I am going to say it is because you still have a buffered CR/LF - so the first one is set to blank. Notice the blank line as you print your family names (numbers). That is your blank family name.

    The keyboard input is a buffered stream - it has your 5, and it has a CR/LF (or perhaps just a LF, depending on your OS).

    You probably want to get the LINE and then do a string.convert, atoi, system.convert (whichever one is for Java) to get the #.

提交回复
热议问题