java内部类的编译和运行
package je3.classes;
public class Averager
{
private int n=0;
private double sum=0.0,sumOfSquares = 0.0;
public void addDatum(double x){
n++;
sum += x;
sumOfSquares += x*x;
}
public double getAverager(){return sum/n;}
public double getStandardDeviation(){
return Math.sqrt(((sumOfSquares - sum*sum/n)/n));
}
public double getNum(){return n;}
public double getSum(){return sum;}
public double getSumOfSquares(){
return sumOfSquares;
}
public void reset(){n=0;sum=0.0;sumOfSquares=0.0;}
public static class Test
{
public static void main(String args[]){
Averager a =new Averager();
for(int i=1;i<=100;i++) a.addDatum(i);
System.out.println("Averager:" + a.getAverager());
System.out.println("Standard Deviation:"+ a.getStandardDeviation());
System.out.println("N:"+a.getNum());
System.out.println("Sum: "+a.getSum());
System.out.println("Sum of squares: "+a.getSumOfSquares());
}
}
}
这段代码编译后在cmd里输入 java je3.classes.Averager 然后编译器显示未找到Main函数,我的main写在内部类里面了,要怎么写命令它才能编译通过呢?
------解决方案--------------------main方法写在内部类里面,所以执行的时候应该
java je3.classes.Averager.Test
1楼的好好看看static关键字