附件是我正在练习的一些java代码。我对此非常陌生并且看起来似乎很小但我可以使用一点帮助来解决我的错误。任何反馈意见都将受到赞赏。
package javaapplication28;
import java.io.*;
import java.util.Scanner;
import java.util.Random;
/**
*
* @author dustin
*/
public class JavaApplication28 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
System.out.println("How many games of Black Jack do you want to play? ");
int g = scanner.nextInt();
System.out.println("How much would you like to bet per hand? ");
int bet = scanner.nextInt();
Random rand = new Random();
int player = 0;
int dealer = 0;
int won = bet * 2;
int blackjack = 0;
String games = Integer.toString(g);
switch(games)
{
case "1":
for (int i = 0; i < g; i++)
{
blackjack = rand.nextInt((21 - 1) + 1);
System.out.print(blackjack);
dealer += player;
}
System.out.println("");
System.out.println("Dealer wins");
break;
case "2":
for (int i = 0; i < g; i++)
{
blackjack = rand.nextInt((21 - 1) + 1);
System.out.print(blackjack);
dealer -= player;
}
System.out.println("");
System.out.println("Player wins");
break;
if (dealer >= player){
System.out.println("Dealer wins!" +blackjack+ ".");
}
break;
else (dealer <= player)
{
System.out.println("Player wins" +won+ " dollars!");
}
break;
}``
}
}
答案 0 :(得分:0)
大小写“2”在if语句之前包含一个break,这将使其无法访问。
在案例结束时有一个中断将使if语句运行。
case "2":
for (int i = 0; i < g; i++)
{
blackjack = rand.nextInt((21 - 1) + 1);
System.out.print(blackjack);
dealer -= player;
}
System.out.println("");
System.out.println("Player wins");
if (dealer >= player) {
System.out.println("Dealer wins!" +blackjack+ ".");
} else (dealer <= player) {
System.out.println("Player wins" +won+ " dollars!");
}
break;
}