cannot find symbol - variable minDist
即使我知道它已被声明和初始化,我也会不断收到此错误。我觉得它正直直地盯着我的脸。有谁知道为什么会这样?
还有另一个类文件与此相关,但我认为错误不在其中。
当我到达时,我在倒数第三行得到它minDist
,但如果我删除它,minDist
我也会得到它。minCost
minMPG
public class AnnualFuelUseTester
{
public static void main(String[] args)
{
int sMiles1, sMiles2, sMiles3, sMiles4;
int eMiles1, eMiles2, eMiles3, eMiles4;
int[] dist = new int[4];
double gals1, gals2, gals3, gals4;
double[] MPG = new double[4];
double price1, price2, price3, price4;
double[] cost = new double[4];
AnnualFuelUse[] fillUps = {new AnnualFuelUse(108438, 108725, 13.9, 2.98),
new AnnualFuelUse(108738, 109023, 15.3, 3.02),
new AnnualFuelUse(109023, 109232, 10.3, 3.05),
new AnnualFuelUse(109564, 109854, 13.1, 3.03)};
for(int i = 0; i < fillUps.length; i++)
{
dist[i] = fillUps[i].calcDistance();
MPG[i] = fillUps[i].calcMPG();
cost[i] = fillUps[i].calcCost();
}
for (int i = 0; i < dist.length; i++)
{
int maxDist = 0;
int minDist = dist[0];
if (dist[i] > maxDist)
{
maxDist = dist[i];
}
if (dist[i] < minDist)
{
minDist = dist[i];
}
}
for (int i = 0; i < dist.length; i++)
{
double maxMPG = 0;
double minMPG = MPG[0];
if (MPG[i] > maxMPG)
{
maxMPG = MPG[i];
}
if (MPG[i] < minMPG)
{
minMPG = MPG[i];
}
}
for (int i = 0; i < dist.length; i++)
{
double maxCost = 0;
double minCost = cost[0];
if (cost[i] > maxCost)
{
maxCost = cost[i];
}
if (cost[i] < minCost)
{
minCost = dist[i];
}
}
System.out.printf("%15s%15s%15s%15s%15s%15s%15s%15s%15s\n\n"
,"Fill Up", "Days", "Start Miles", "End Miles"
,"Distance", "Gallons Used", "MPG", "Price", "Cost");
for(int i = 0; i < fillUps.length; i++)
{
System.out.printf("%15s%15s%15s%15s%15s%15s%15.2f%15s%15.2f\n"
,(i+1),(int)(1 + i *(i*1.1)), fillUps[i].getmySMiles()
,fillUps[i].getmyEMiles(), dist[i]
,fillUps[i].getmyGals(), MPG[i]
,fillUps[i].getmyPrice(), cost[i]);
}
System.out.printf("%10s%10s%30s%30s","Minimum",minDist,minMPG,minCost);
}
}