-5
有人可以告诉我需要做些什么改变才能摆脱这个错误,为什么会发生这种情况?线程“main”中的异常Java中的java.lang.ArrayIndexOutOfBoundsException:0错误
public class Gambler {
public static void main(String[] args) {
int stake = Integer.parseInt(args[0]); // gambler's stating bankroll
int goal = Integer.parseInt(args[1]); // gambler's desired bankroll
int T = Integer.parseInt(args[2]); // number of trials to perform
int bets = 0; // total number of bets made
int wins = 0; // total number of games won
// repeat T times
for (int t = 0; t < T; t++) {
// do one gambler's ruin simulation
int cash = stake;
while (cash > 0 && cash < goal) {
bets++;
if (Math.random() < 0.5) cash++; // win $1
else cash--; // lose $1
}
if (cash == goal) wins++; // did gambler go achieve desired goal?
}
// print results
System.out.println(wins + " wins of " + T);
System.out.println("Percent of games won = " + 100.0 * wins/T);
System.out.println("Avg # bets = " + 1.0 * bets/T);
}
}
Probabaly因为没有3个参数数组中的'args' ...你甚至懒得检查? – James
哪一行?当你寻求帮助时,尽可能多地提供有用的信息是一个好主意。 – Smittey
第四行int股份....... – susa1012