Click here to Skip to main content
16,017,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am new in Java technology.
I would like to pass a integer value in InputStreamReader.
Java
InputStreamReader is=new InputStreamReader(rn);
   BufferedReader object=new BufferedReader(is);
  int answer=Integer.parseInt(object.readLine());

Here rn is a random number, I would like to pass, but it's showing an error.

Thank you
Posted
Updated 29-Nov-12 23:49pm
v3

1 solution

That will not work - cause Inputreader is waiting for some input stream and not for an assigned value.

You do not need to do all of the above. Just create a random number from scratch:

Java
/* will generate a int value in the space 0 to 99
 *(cause computers and all beeing aside of humans are counting from 0).
 */
Random oRandom = new Random();
int iRandom = oRandom.nextInt(100); 


You can find some more examples here: http://www.javapractices.com/topic/TopicAction.do?Id=62[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900