【发布时间】:2014-04-27 10:39:19
【问题描述】:
问题是在 User2 之间的输入不被接受?
public static void main() throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int user1total = 0, user2total=0, i;
char userchoice;
System.out.println("Welcome to the game of BlackJack!!!");
System.out.println("User1 will be drawing two cards at a time");
System.out.println("User2 will also be drawing two cards at a time");
System.out.println("User1 shall win if User1's total reaches 21 or the User2's total exceeds 21");
System.out.println("User2 shall win if User1's total reaches 21 or the User1's total exceeds 21");
for(i=0;i<=4;i++)
{
System.out.println("User1's Total ="+user1total);
System.out.println("User2's Total ="+user2total);
if(user1total>21)
{
System.out.println("User2 wins as User1's total has exceeded 21");
System.exit(0);
}
if(user2total>21)
{
System.out.println("User1 wins as User2's total has exceeded 21");
System.exit(0);
}
if(user1total==21)
{
System.out.println("User2 wins as his total is 21");
System.exit(0);
}
if(user2total==21)
{
System.out.println("User1 wins as his total is 21");
System.exit(0);
}
System.out.println("Want to take two more cards, User1???");
System.out.println("Enter Y or N");
userchoice = Character.toUpperCase( (char)in.read() );
if (userchoice=='Y')
user1total=user1total+randomnumbersforuser();
System.out.println("User1's Total ="+user1total);
System.out.println("User2's Total ="+user2total);
System.out.println("Want to take two more cards, User2???");
System.out.println("Enter Y or N");
userchoice = Character.toUpperCase( (char)in.read() ); ***//This part does not take input at all***
if (userchoice=='Y')
user2total=user2total+randomnumbersforuser();
System.out.println("User1's Total ="+user1total);
System.out.println("User2's Total ="+user2total);
}
if(user1total>user2total)
System.out.println("User1 wins as his final total is greater than User2's total");
if(user2total>user1total)
System.out.println("User2 wins as his final total is greater than User1's total");
}
}
【问题讨论】:
-
我建议你学习调试。
-
不要让任何人告诉你因为你才 14 岁就不能做某事!不过说真的,如果人们使用您不熟悉的术语,Google it!。
-
是的,debug。
-
@GoldRoger:这个答案与这个问题无关。
-
@Yuki 不,这正是问题所在..
\n输入键是从第一个read留下的,第二个read使用它而不是用户输入..无论如何我给了链接扫描仪..删除它