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; } } }

2nd May 2020, 5:42 AM
Shivam Rawal
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.
2nd May 2020, 6:21 AM
Ipang
+ 1
Yes it is about Fibonacci
2nd May 2020, 6:29 AM
Shivam Rawal
+ 1
Tysm
2nd May 2020, 6:30 AM
Shivam Rawal