Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Input

 
Sadaf Zaidi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic