help me on use input data JAVA

5 pts.
Tags:
Java
Java developers
Java programming
Hello friends I encountered a problem i,e
import java.io.*;
public class execute {
public static void main(String args[])throws Exception{
char cname;
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter a letter");
cname= (char)br.read();
if(cname==' '){
System.out.println("u entered a space");
}
else {
System.out.println("u entered a character");
}
}
}
In the above program, help in writing a loop such that
until and unless a character is entered(as input from keyboard) ,it should keep asking me to "Enter a character"


Software/Hardware used:
eclipse
ASKED: March 18, 2010  4:04 AM
UPDATED: November 5, 2011  4:27 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

lets keep the code in the try block if the input is any space u keep it in that and catch in catch block or in finally block u keep the loop.It might solve ur problem

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • shiva3322
    lets keep the code in the try block if the input is any space u keep it in that and catch in catch block or in finally block u keep the loop.It might solve ur problem
    660 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following