Re: Help with a loop




"Fish" <Fish@xxxxxxxxxxx> wrote in message
news:pccp14d7jbtdurf5dme06n5e7952ji7pue@xxxxxxxxxx
Could a kind Java code expert take a look at a method for me?

It seems that once called, the method starts out good by
creating/opening up a file (appending existing files). It hiccups
when it gets to the do loop. It asks the first question, then without
waiting for data to be entered, it asks the second question. This
only happens on the first iteration of the loop.


(snip)

Scanner keyboard = new Scanner(System.in);
String fileName = keyboard.next();


If you change the above line to :
String fileName = keyboard.nextLine();
the problem goes away. I'm not sure why exactly, but maybe next() leaves
something in the input that is picked up by the first nextLine() in the
loop.


.



Relevant Pages

  • Re: Basic file operation questions
    ... > I am a beginner with python and here is my first question: ... > How can I read the contents of a file using a loop or something? ...
    (comp.lang.python)
  • Re: Help with a loop
    ... creating/opening up a file (appending existing files). ... It hiccups ... It asks the first question, ... only happens on the first iteration of the loop. ...
    (comp.lang.java.help)
  • Re: Small arrays and loop performance
    ... The first question to ask is whether it matters. ... waste a lot of time "optimizing" the performance of something where the ... going to make a significant difference to the utility of the ... straightforward (which I'd guess to be the loop - but you can evaluate ...
    (comp.lang.fortran)
  • Re: Help with a loop
    ... creating/opening up a file (appending existing files). ... It hiccups ... It asks the first question, ... only happens on the first iteration of the loop. ...
    (comp.lang.java.help)
  • Basic file operation questions
    ... I am a beginner with python and here is my first question: ... How can I read the contents of a file using a loop or something? ...
    (comp.lang.python)