Question #4166

I want to output 0,1,1,2,3,5,8,13,21,34

Expert's answer

public class Fibonacci{ public static void main(String[] args){
int current = 1;
int previous = 0;
int temp =0;
while (current<50){
temp = current;
System.out.println(current);
current = previous + current;
previous = temp;
}
}
}
LATEST TUTORIALS
APPROVED BY CLIENTS