Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
System.in.read()
Arun Prasath
Ranch Hand
Posts: 60
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Why doesn't the following snippet ask for input values 3 times
from the user input keyboard?
Rather ,its asks only for one time...and directly goes to the next
line following the loop.
for(int i=0;i<3;i++){
char c=(char)System.in.read();
}
Satyanarayana Veera Venkata
Greenhorn
Posts: 4
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
try increasing the loop count to 10
for(int i=0;i<[B]10[/B];i++){ char c=(char)System.in.read(); } and instead of entering a word on the sameline, enter one character at a time (one character, hit enter) for example, if you type this, r <hit enter> o <hit enter> m <hit enter> e <hit enter> your program will surely wait for your input multiple times. reason is, read gets one byte at a time. after r enter , variable i will be 3, after o enter variable will be 6. What happened here is when i = 0 read returns r when i = 1 read returns 13 (character will not be visible, but surely a byte had entered the stream) when i = 2 read returns 10 (character will not be visible) bytes 13,10 are put into the input stream as soon as enter key is hit if you add a println to print each char, you can see it yourself for (int i = 0; i < 10; i++) { int n = System.in.read(); System.out.println(i + "time " + "char #" + n); } console output r 0time char #114 1time char #13 2time char #10 o 3time char #111 4time char #13 5time char #10 m 6time char #109 7time char #13 8time char #10 e 9time char #101
Satyanarayana Veera Venkata
Greenhorn
Posts: 4
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Arun,
i am wondering how you could put the code snippet in normal font. after several tries i chose to put entire text as CODE, couldnt mix code and text.
Satya
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
math program help..
Basic Java Problem....HELP!!!!
donno if its certification related
unicode value for char
Reading a Character
More...