SeamyMal
SeamyMal

Reputation: 1

Pressing "Enter" to start Java program again

I'm very new to Java and I am not very sure about it just yet. My friend and I have been playing around with a program where we input text and it gives us the frequency and the word count of the sentence.

When it comes to the end of the program, we would like to add in an option to press "Enter" to start again, but we are not sure what code to write at all and where about in the program it should go.

Any help would be appreciated!

Pastebin Link to our code: http://pastebin.com/6x0qkNt0

Upvotes: 0

Views: 1287

Answers (1)

jasper
jasper

Reputation: 355

What you probably want to do is to create a loop:

String answer = "y";
while(answer.equals("y")){
   runProgram();
   [...]
}

Call your existing code inside the {} and prompt the user to enter 'y' if he wants to continue using the program instead of the [...]. Looking at your code I'd say some cleanup might be a good idea.

Upvotes: 1

Related Questions