我正在学习Java。今天,我的任务是查找某些代码中的错误。我正在研究它,但是我不知道为什么会发生以下错误。在示例代码中,它在“ int momsAge = 42; dadsAge = 43;”行上为我提供了“ .class期望”。特别是,它在momsAge的前面放置了一条错误线。

// A class that computes the sample statistics of the ages of
// family members.
public class FamilyStats
{
public static void main(String[] args)
{
/*
math equations obtained from: */
http://mathworld.wolfram.com/SampleVariance.html

// define some ages

int momsAge= 42; dadsAge= 43;
int myAge= 22, sistersAge= 16;
int dogsAge= 6;

// get the mean

double ageSum = (momsAge + dadsAge + myAge + sistersAge + DogsAge);
double average = ageSum / 5

/ calculate the sample variance
double variance= 0.0;
variance += (momsAge - average)*(momsAge - average);
variance += (dadsAge - average)(dadsAge - average);
variance += (myAge - average)*(myAge - average);
variance += (sistersAge - average)*(sistersAge - average);
variance += (dogsAge - average)*(dogsAge - average);
variance = variance / 4;

// get the std. dev
double standardDev= Math.sqrt(variance);
// output the results
System.out.println("The sample age mean is: " + average);
System.out.println("The sample age variance is: " + variance);
System.out.println("The sample age standard deviation is: " + standardDev);
}
}

最佳答案

int momsAge= 42; dadsAge= 43;


应该

int momsAge= 42, dadsAge= 43;


;用作语句的末尾,因此实际上就是您的下一条语句

dadsAge = 43;

显然这是错误的,因为需要一个类。使用,可以链接这些分配。

也:

http://mathworld.wolfram.com/SampleVariance.html

没有评论(至少http:部分没有)。

09-30 10:50