- #1
BrandNewDay
- 1
- 0
I don't know why in the main method, the do-while loop won't work the way it's supposed to.
For instance, if the user types in y, the first loop would execute and then since the value of choice is still 'y', it's supposed to loop again. But instead, it just displays "TOSS COIN? Press y for yes." without asking for a new value of choice. What's wrong with it?
For instance, if the user types in y, the first loop would execute and then since the value of choice is still 'y', it's supposed to loop again. But instead, it just displays "TOSS COIN? Press y for yes." without asking for a new value of choice. What's wrong with it?
Code:
do{
System.out.print("TOSS COIN? Press y for yes.");
choice = (char)System.in.read();
if(choice == 'y' || choice == 'Y')
{
Coins c = Coins.flip();
System.out.println(c);
if(c == Coins.HEAD)
heads++;
else
tails++;
}
}while(choice == 'y' || choice == 'Y');