import java.util.Scanner;
public class FiboNacci {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int a = 0;
int b = 1;
int sum = a+b;
while(a<=n) {
if(n==0) {
System.out.println(a);
a= a+1;
} else if (n==1) {
System.out.println(b);
} else {
System.out.println(sum);
a = b;
b = sum;
}
}
scn.close();
}
}
My code is looping at 1 in console and just goes in. What is wrong with my approach. I wanted to try and form my own solution for this problem. Kindly let me know my mistake, why is it looping, and how I can correct it?