设计一个名为 IntSequence 的接口表示整数序列,该接口包含 boolean hasNext()和
int next()两个方法。定义一个名为 RandomIntSequence 的类实现 IntSequence 接口,其中包含一个 private 整型变量n。在 hasNext()方法中随机生成一个两位整数,存储到变量n中,然后返何true。在 next()方法中返回n的值。
package com.banji.xy;
public class RandomIntSequence implements IntSequence {
private int n;
public boolean hasNext() {
n = 10 + (int) (Math.random() * 90);
return true;
}
public int next() {
return n;
}
public static void main(String[] args) {
IntSequence sequence = new RandomIntSequence();
System.out.println(sequence.hasNext());
System.out.println(sequence.next());
}
}
package com.banji.xy;
public interface IntSequence {
public abstract boolean hasNext();
public abstract int next();
}