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 + ",": ""));
}
}
Result :
0,1,
1,2,
3,5,
8,13,
21,34,
55,89,
Top comments (1)
Welcome to add your comments :)