2

I want to read input from a console for example
Enter input:
aabbbab
execute the method when pressed Enter and keep asking for input and execute till a character is typed in. At the moment I can read an input and enter it execute it.Then I need to run a program again to enter a new input.

1
  • It is always a good idea to post sample code along with your questions if applicable, as it helps others diagnose more effectively. Commented Sep 3, 2009 at 22:31

3 Answers 3

5
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
while(true){
    String text = console.readLine();
    doStuff(text)
}
Sign up to request clarification or add additional context in comments.

Comments

0

I think what you are asking for is to do something (in this case taking input and working on it) repeatedly. It should be clear that when you want to do the same thing repeatedly, you should put that code inside a loop. What that loop looks like (e.g. for, do, while etc.) and what its exit condition is, is up to you.

Comments

0

We can read string from console application using console class

 String username = console.readLine("Enter username: ");
 System.out.println(username);

1 Comment

Your answer adds nothing to this question than what has already been said - except the link to your blog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.