问题在于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");
}
}
答案 0 :(得分:0)
String[] args
作为参数添加到main。 public static void main(String[] args)
throws
。你不能让main
扔东西。无处可扔。userchoice
。在开头插入行char userchoice = 0;
。您的代码现在应该可以使用。