0
Can anyone tell me why the output is only 0 & 1
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int a = 0; int b= 1; int c; System.out.print(a+" "); System.out.print(b+" "); for (int i=1;i==(n-2);++i){ c= a+b; System.out.print(c + " "); a=b; b=c; } } }
3 Réponses
+ 5
Is this code about Fibonacci sequence? anyways, you can try to change your for-loop as follows
for(int i = 1; i < (n - 1); i++)
The loop doesn't even run because the condition is `i == (n - 2)` which is false from the beginning of loop.
+ 1
Yes it is about Fibonacci
+ 1
Tysm