Discuss / Java / 作业

作业

Topic source

shadowTy

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {
	public static void main(String[] args) throws IOException {
		LongStream fib = LongStream.generate(new FibSupplier());
		// 打印Fibonacci数列:1,1,2,3,5,8,13,21...
		fib.limit(10).forEach(System.out::println);
	}
}
class FibSupplier implements LongSupplier {
	int f = 0;
	int s = 1;
	boolean flag = true;
	public long getAsLong() {
		int c = f + s;
		f = s;
		s = c;
		return f;
	}
}

  • 1

Reply