Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Mada Akhtar   on May 10 In Java Category.

  
Question Answered By: Huette Miller   on May 10

Well, int is 4 bytes and char  is 2 bytes
long. But even then ur explanation should have been correct. But i tried
to change the code  as
input = System.in.read();
choice = (char) input;
But the problem  remained. However the explanation given by Pallav (See
below) was found to be correct. When i gave the input  9<space>1<enter>it
first redisplayed the menu  twice but the second time automatically went
to the switch  case associated with choice  1.

I guess it stores the input we enter in a buffer and takes its input
from there. So the next question is how do i correct this? That is after
it takes the first input, how do i flush the buffer???

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Problem with System.in.Read() Or get search suggestion and latest updates.


Tagged: