1.喜闻乐见的被应用类加static来实现,但这并不符合所有情况
2.要使用以下写法:new 父类().new 子类();
public static void main(String[] args) {
MovingAverage test2=new No346().new MovingAverage(3);
//错误写法
//MovingAverage test=new MovingAverage(3);
}
public class No346 {
public class MovingAverage {
/** Initialize your data structure here. */
private IntCircularQueue q;
public MovingAverage(int size) {
q = new IntCircularQueue(size);
}
public double next(int val) {
q.offer(val);
int sum = q.getSum();
int n = q.getCrrSize();
double d1 = sum;
double d2 = n;
double res = d1 / d2;
return res;
}
}
}
参考链接