aspose file tools*
The moose likes Beginning Java and the fly likes .nextLine() looping error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ".nextLine() looping error?" Watch ".nextLine() looping error?" New topic
Author

.nextLine() looping error?

Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Hey guys whenever I run this script and go to the help area, it messes up and loops a bunch of times.

Not sure how to fix it but heres the code.

Error is at 40-50 lines into the code.



If your wondering what I'm trying to do, I'm trying to make a basic text based game.
Justin Hawtree
Greenhorn

Joined: Jul 27, 2012
Posts: 3

Line 44 needs
typed = input1.nextLine();

The reason is you need to accept a new input or it uses the old one and keeps looping
Edit:
But the main reason why it is looping is because you need to wait for the user input each time you go into the Help method.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Hi Jake and Justin, and welcome to the Ranch! Jake, you really need to go through the coding conventions for the Java programming language. Your class name should start with an uppercase letter, all method and variable names with a lowercase letter.

If the recursion in the help() method isn't a requirement of the exercise, it's not necessary. A while or do..while loop would do just as well, and express the intention better.

Also, are you aware that a method can have a return statement that returns program flow to the calling code? and that the return statement can even be inside a code block like an if (...) {...} statement or a while (...) {...) loop?


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .nextLine() looping error?
 
Similar Threads
getting java.lang.NoSuchMethodError: main error! thanks =)
can anyone please briefly teach me how to write a classic game?
Having issues with sub menu causing main menu to not exit
Help with writing to a file!
method construction trouble