我遇到的问题是最后一行。我在此部分收到错误消息,指出" 找不到符号"。这不是我的整个程序,只是第一部分。
public class Chap6Project
{
public double shooterExperiment(int dualsPerExperiment, String[] shooters, double[] accuracies, ProbabilitySupplier p)
{
shooters[0] = "aaron";
shooters[1] = "bob";
shooters[2] = "charlie";
String aaron = shooters[0];
String bob = shooters[1];
String charlie = shooters[2];
accuracies[0] = 0.33;
accuracies[1] = 0.5;
accuracies[2] = 1.0;
int duelCount = 0;
boolean aaronAlive = true;
boolean bobAlive = true;
boolean charlieAlive = true;
Chap6Project project = new Chap6Project();
ProbabilitySupplier random = new ProbabilitySupplier();
double rateOfSuccess = project.shooterExperiment(1000, shooters, accuracies, random);
while (duelCount < 1000)
{
int aaronKills = 0;
int aaronWin = 0;
double aaronAccuracy = random.getAsDouble();
if (aaronAccuracy == 0.33)
{
if (charlieAlive != true)
{
aaron.shooterExperiment(1000, bob, accuracies[1], random);
答案 0 :(得分:0)
你声明aaron变量是这样的:
textarea
然后尝试使用它:
String aaron = shooters[0];
并在此方法中执行此操作:
aaron.shooterExperiment(1000, bob, accuracies[1], random);
aaron变量是一个字符串,字符串没有public double shooterExperiment(int dualsPerExperiment, String[] shooters,
double[] accuracies, ProbabilitySupplier p)
方法。也许你打算在另一个变量上调用这个方法?鉴于你发布的内容,很难说。看起来你试图从内部调用shooterExperiment(...)
方法,这意味着进行递归调用,并使用不正确的方法参数和错误的对象,一个String对象,这些都没有意义。< / p>
您需要澄清您的问题以及您的代码应该做些什么。
其他问题: