Java 我自己做了一个21点游戏,但是程序的一部分没有执行
问题是,中间用户2的输入不被接受Java 我自己做了一个21点游戏,但是程序的一部分没有执行,java,input,blackjack,Java,Input,Blackjack,问题是,中间用户2的输入不被接受 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
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");
}
}
publicstaticvoidmain()引发IOException
{
BufferedReader in=新的BufferedReader(新的InputStreamReader(System.in));
int user1total=0,user2total=0,i;
字符用户选择;
System.out.println(“欢迎来到21点游戏!!!”;
System.out.println(“User1将一次绘制两张卡”);
System.out.println(“User2一次还将绘制两张卡”);
System.out.println(“如果用户1的总数达到21或用户2的总数超过21,则用户1应获胜”);
System.out.println(“如果用户1的总数达到21或用户1的总数超过21,则用户2应获胜”);
对于(i=0;i21)
{
System.out.println(“User2赢了,因为User1的总数超过了21”);
系统出口(0);
}
如果(user2total>21)
{
System.out.println(“User1赢了,因为User2的总数超过了21”);
系统出口(0);
}
如果(user1total==21)
{
System.out.println(“User2赢了,因为他的总数是21”);
系统出口(0);
}
如果(user2total==21)
{
System.out.println(“User1赢了,因为他的总数是21”);
系统出口(0);
}
System.out.println(“想再拿两张卡吗,User1?”);
系统输出打印项次(“输入Y或N”);
userchoice=Character.toUpperCase((char)in.read());
if(userchoice=='Y')
user1total=user1total+randomnumbersforuser();
System.out.println(“User1的总计=”+user1total);
System.out.println(“User2的总计=”+user2total);
System.out.println(“想再拿两张卡吗,User2?”);
系统输出打印项次(“输入Y或N”);
userchoice=Character.toUpperCase((char)in.read());***//此部分根本不接受输入***
if(userchoice=='Y')
user2total=user2total+randomnumbersforuser();
System.out.println(“User1的总计=”+user1total);
System.out.println(“User2的总计=”+user2total);
}
如果(user1total>user2total)
System.out.println(“User1赢了,因为他的最终总数大于User2的总数”);
如果(user2total>user1total)
System.out.println(“User2赢了,因为他的最终总数大于User1的总数”);
}
}
String[]args
作为参数添加到main<代码>公共静态void main(字符串[]args)抛出
。你不能让main
抛出一些东西。没有地方可以扔userchoice
。插入行char userchoice=0代码>在开头
你的代码现在应该可以工作了。我建议你学会调试。不要让任何人告诉你你不能做什么,因为你才14岁!说真的,如果人们用一个你不熟悉的词,是的,@GoldRoger:这个答案与这个问题无关。@Yuki No这正是问题所在。
\n
回车键是从第一个读取
留下的,第二个读取
代替了用户输入。。无论如何,我给了扫描程序的链接。。删除它1。只有在需要方法调用窗口时才需要字符串[]参数,我不需要。2.throws是一个关键字,用于将IOException链接到main,因此我需要它。3.当值直接更改为用户输入时,userchoice不需要设置为零。即使我要将其实例化,我也会将其实例化为“”,而不是0。