0

As of now, my program completely skips over allowing the user to enter input into the var "runAgain". I understand putting "myScanner.nextLine();" directly after runAgain would fix this problem. However it also requires the user to enter again. I would like to avoid this if possible. Any solutions? Thanks.

System.out.print("\nRun #" + count + "? ");
runAgain = myScanner.nextLine();
    if ()  {
        end program;
    }
    else {
        re-run program;
    }
Jonathan Mousley
  • 113
  • 1
  • 1
  • 5
  • 3
    _However it also requires the user to enter again._ What makes you think so? Please post an [MCVE]. – Sotirios Delimanolis Jul 12 '16 at 22:14
  • Also, why aren't you using `Arrays.asList()` instead of the awkward, memory-leak-prone double-brace style? – Louis Wasserman Jul 12 '16 at 22:19
  • Leaving [this](http://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-other-nextfoo-methods?rq=1) here as a potential duplicate target. – Sotirios Delimanolis Jul 12 '16 at 22:21
  • @SotiriosDelimanolis I tried it and that's what happened. – Jonathan Mousley Jul 12 '16 at 22:23
  • Is it possible that you used your scanner earlier to read some other token via `next()` or `nextInt()` or other `next*Type*()` method? If that is the case then check [Skipping nextLine() after using next(), nextInt() or other nextFoo() methods](https://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-other-nextfoo-methods) – Pshemo Jul 12 '16 at 22:34
  • @Pshemo I believe that was the problem. I ended up just making two different scanners. One for lines, the other for doubles and integers. Thanks for the help and patience, guys! – Jonathan Mousley Jul 12 '16 at 22:39
  • @LouisWasserman could you post a code example for that method? Thanks for your time in advance! – Jonathan Mousley Jul 12 '16 at 22:42
  • @JonathanMousley are you looking for `List negativeResponse = Arrays.asList("n", "N", "no", "No", "NO", "0");` ? – Louis Wasserman Jul 12 '16 at 22:44
  • @LouisWasserman yes. Thank you! – Jonathan Mousley Jul 12 '16 at 22:45

0 Answers0