Java 数组不获取值
我对以下代码有问题Java 数组不获取值,java,arrays,nullpointerexception,Java,Arrays,Nullpointerexception,我对以下代码有问题 public static void SideBet(int numberDice,int bet,int money) { System.out.println("You established a " + "\""+ "point" + "\"" + ". " + "Your " + "\""+ "point" + "\"" + " is " + numberDice + ". " + "You have to roll a(n) " + numberDi
public static void SideBet(int numberDice,int bet,int money) {
System.out.println("You established a " + "\""+ "point" + "\"" + ". " + "Your " + "\""+ "point" + "\"" + " is " + numberDice + ". " + "You have to roll a(n) " + numberDice + " to win your bet, "+ bet +" chips." );
System.out.println();
System.out.println("You can put side bets for 4,5,6,8,9 or 10.");
SideBetChoice = Console.readLine("Would you like to make any side bets ? (Type " + "\""+ "Yes" + "\"" + " or "+ "\""+ "No" + "\"" + ", then hit Enter.)");
int s = 0;
int r = 0;
if (SideBetChoice.equals("Yes")) {
System.out.println("You can put as many side bets as you would like for the numbers 4,5,6,8,9 or 10.");
int SideBetNumber = Console.readInt("How many side bets would you like to make ? (Introduce a number, minimum 1, maximum 6.)");
int[] SBNArray = new int[SideBetNumber];
int[] sbArray = new int[SideBetNumber];
for (s = 0; s <= (SideBetNumber -1) ; s++) {
SBNArray[s] = Console.readInt("On which number would you like to put a side bet ?");
sbArray[s] = Console.readInt("Currently you have " + money + " chips, how much would you like to bet ?");
money = money - sbArray[s];
System.out.println("Thank you for your " +sbArray[s]+ " chip side bet on number " +SBNArray[s]+".");
System.out.println();
}
}
if (SideBetChoice.equals("No")) {
return;
}
公共静态无效侧注(整数、整数下注、整数货币){
System.out.println(“你建立了一个“+”\“+”点“+”\“+”+”点“+”\“+”点“+”\“+”点是“+numberDice+”””+“+”你必须掷一个(n)“+numberDice+”才能赢得赌注,“+bet+”筹码“);
System.out.println();
System.out.println(“您可以为4、5、6、8、9或10进行单边下注”);
SideBetChoice=Console.readLine(“您想进行任何单边下注吗?(键入“+”\“+”是“+”\”+”或“+”\“+”否“+”\”+”,然后按Enter键)。”;
int s=0;
int r=0;
if(SideBetChoice.equals(“是”)){
println(“您可以对数字4、5、6、8、9或10进行任意数量的侧注”);
int SideBetNumber=Console.readInt(“您希望进行多少次侧注?(引入一个数字,最小1,最大6”);
int[]SBNArray=新int[SideBetNumber];
int[]sbArray=新int[SideBetNumber];
对于(s=0;s,控制台中没有readInt()方法。
另外,我不确定您是否正确使用了console,它应该如下所示:
Console console = System.console();
console.readLine("Type something");
只需使用readLine()并将其转换为int:
Console console = System.console();
String input = console.readLine("Type a number");
try
{
int myNumber = Integer.parseInt(input);
}
catch(NumberFormatException e)
{
System.out.println("This ain't a number!");
}
另外,请不要在变量名或方法名中使用大写字母,这很容易混淆,因为您可能会认为它是一个类或类型。
因此,请更改SBNArray的名称和SideBetNumber、SideBetChoice等。
仅常量应仅用大写字母书写,类和类型应以大写字母开头
编辑:
很抱歉,您似乎正在使用BreezyGUI.Console,因此有一个readInt()方法
你能提供更多的信息吗?
我想知道readInt()的文本甚至显示。SideBetChoice从来没有用类型声明过。它在程序中声明过吗?什么是Console
?如果它是java.io.Console
我认为它没有readInt
方法。它是Scanner
实例吗?如果是,它是nextInt
而不是readInt
公共静态控制台e input=new Console();控制台没有问题……我将检查SideBetChoicepublic静态字符串SideBetChoice=“”;在main中声明为String它在哪一行崩溃?