File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Input" Watch "Input" New topic
Author

Input

Sadaf Zaidi
Greenhorn

Joined: Oct 09, 2001
Posts: 29
I have to generate random characters from A to Z and then take input from the user if user hits the wrong alphabet then I wants to give him a 4 chances for which
I wants to take input five times from the user for this :
tell me how to get input from the user 4 times .
public class Tests
{
public static void main(String[]args)
{
char ch;
char input=' ';
ch=(char)(Math.random()*(90-65)+65);
for(int i=0;i<4;i++)
{
System.out.println("Enter a value");
try
{input=(char)System.in.read();}
catch(Exception e)
{ }
}
}
}

[This message has been edited by Sadaf Zaidi (edited October 31, 2001).]
Argm Mastoi
Ranch Hand

Joined: Oct 16, 2001
Posts: 35
The problem i'm facing is the code for Input from the user is running only once, rather i call it 4-5 times in the programe but
the program terminates after 1st input.
I tried to check it in a loop also but if the loop goes 4 times, all 4 chars are given at once then it is ok otherwise after enter it takes no input. It should take 4 chars one by one after input but it is not taking it i don't know why.
can u please help.
 
GeeCON Prague 2014
 
subject: Input