This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read int or any input value entered in console using DataInputStream??  RSS feed

 
prasad kakani
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

Could you please tell me how to read the int or any input value which is entered in console while executing the program, using DataInputStream..

suppose System.out.println("Enter the Range:");
DataInputStream dis = new DataInputStream(System.in);
int range = dis.read();
System.out.println("The range is "+ range);

i think i am doing something wrong here..please suggest me..
Thanks
Prasad
 
Christian Zillmann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why using DataInputStream for that ?
 
Gareth Lloyd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I think you need to use readInt() rather than read()

Take a look at the JavaDoc for DataInputStream's various methods:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataInputStream.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!