Print out Fibonacci numbers in range 0 – 100
Concept : print out two numbers every time
Code in java:
public class fibonacci {
public static void main(String[] args) {
for(int a = 0, b=1; a < 100 ; a+=b, b+=a)
System.out.println(a + "," + (b<100 ? b + ",": ""));
}
}
Enter fullscreen mode Exit fullscreen mode
Result :
0,1,
1,2,
3,5,
8,13,
21,34,
55,89,
原文链接:Algorithms Challenge (1) How to print out Fibonacci series in two lines code
© 版权声明
THE END
暂无评论内容