Set Max Value to Fibonacci Series

Description:

Write a java program to Set Max Value to Fibonacci Series Test Case 1 Input (stdin) 20 Expected Output 0 1 1 2 3 5 8 13 Test Case 2 Input (stdin) 45 Expected Output 0 1 1 2 3 5 8 13 21 34

Program :



import java.util.Scanner;

 

public class TestClass {

public static void main(String args[]) {

Scanner scan = new Scanner(System.in);

int max = Integer.parseInt(scan.nextLine());

int a = -1;

int b = 1;

int c = 0;

c = a + b;

while(c <= max) {

int temp = a;

a = b;

b = c;

System.out.println(c);

c = a + b;

}

}

}