BufferedReader is not waiting for an input from user

Here is my code... for some reason, ithe BufferedReader does not wait for input from the user... I have included the output that i get when i run it...

private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

public static void main(String[] args)

throws IOException{

// TODO code application logic here

char c;

int ctr=0;

String str;

System.out.println("Enter a domino?(y/n):");

c= (char) br.read();

while(c == 'y'){

d[ctr]=new domino();

System.out.println("Enter the top string of domino:");

str = br.readLine();

d[ctr].setTopString(str);

System.out.println("Enter the bottom string of domino:");

str = br.readLine();

d[ctr].setBottomString(str);

d[ctr].setName(ctr+1);

System.out.println("Enter another domino?(y/n):");

ctr++;

c= (char) br.read();

}

System.out.println("Done accepting dominos!");

for(int x=0;x<ctr;x++){

System.out.println(d[x].name);

System.out.println(d[x].topString);

System.out.println(d[x].bottomString);

}

Output:

Enter a domino?(y/n):

y

Enter the top string of domino:

Enter the bottom string of domino:

aba

Enter another domino?(y/n):

y

Enter the top string of domino:

Enter the bottom string of domino:

aab

Enter another domino?(y/n):

n

Done accepting dominos!

1

aba

2

aab

you see how it simply does not give me a chance to input the topstrings at all? wat have i overlooked?>

[1635 byte] By [vpaia] at [2007-10-1 4:38:31]
# 1

Prior to these lines

System.out.println("Enter the top string of domino:");

str = br.readLine();

you used this line

c= (char) br.read();

The read left the line separator in the buffer, which was read by the br.readLine.

Do something to either clear the buffer, or use readLine instead of read.

ChuckBinga at 2007-7-9 5:08:31 > top of Java-index,Administration Tools,Sun Connection...
# 2

how can i do that? clear the readLine i mean... and i dont get wat exactly you mean by "left the line separator in the buffer"... i seem to have overcome the problem by giving two readline stmts one after the other, which is clearly not good programming practice, but at least it is getting me ahead... the first readline is ignored, but the second one works just fine. wud love to know wat the real issue is though. thanx!

vpaia at 2007-7-9 5:08:31 > top of Java-index,Administration Tools,Sun Connection...
# 3

When you enter

y<enter>

You enter two keys not one.

Now you read one character, but there is still a character in the buffer. Then you call readLine() which reads the <enter>

The simplest thing to do is just use readLine() and don't use read() as the previous poster suggested.

Peter-Lawreya at 2007-7-9 5:08:31 > top of Java-index,Administration Tools,Sun Connection...
# 4
oooohhhhhh! now i understand! thats super cool... i wud never have thot of it like that. thanx u guys! that was VERY helpful!!!
vpaia at 2007-7-9 5:08:31 > top of Java-index,Administration Tools,Sun Connection...