function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
naveen kunurunaveen kunuru 

can any one help an interview scenario

hello ,i need a code whose o/p will be {1,1,2,3,5,8,13,21,34,55}
loop should rotate 10 times 
this scenario add two num every time when loop rotates;
plzzzzzzzz thanks
Best Answer chosen by naveen kunuru
Ramesh KosalairamanRamesh Kosalairaman
This will be your answer 
Integer loopCount = 10;
list<Integer> FibonacciList = new list<Integer>();
Integer fibo1=0, fibo2=1, fibonacci=1;
FibonacciList.add(fibonacci);
for(Integer i= 0; i< loopCount; i++){
	fibonacci = fibo1 + fibo2; 
	fibo1 = fibo2;
	fibo2 = fibonacci;
	FibonacciList.add(fibonacci);
}
system.debug('Fibonacci number'+FibonacciList);

All Answers

naveen kunurunaveen kunuru
hey i wrote all this in anonymous class if i able to show in log files thats will be grand
naveen kunurunaveen kunuru
basic code what is known is 
integer r=1;

interger j=1;

integer l=r+j;
for(integer i=0,i<10,i++){
    list<integer> k=new list<integer>();
    
    k.add(l);
    
    
    
}
system.debug(''+k);
Ramesh KosalairamanRamesh Kosalairaman
This will be your answer 
Integer loopCount = 10;
list<Integer> FibonacciList = new list<Integer>();
Integer fibo1=0, fibo2=1, fibonacci=1;
FibonacciList.add(fibonacci);
for(Integer i= 0; i< loopCount; i++){
	fibonacci = fibo1 + fibo2; 
	fibo1 = fibo2;
	fibo2 = fibonacci;
	FibonacciList.add(fibonacci);
}
system.debug('Fibonacci number'+FibonacciList);
This was selected as the best answer
naveen kunurunaveen kunuru
hey thanks man,great work