Question: import java.util.Scanner; class FibonacciCount { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in

import java.util.Scanner;
class FibonacciCount {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(countFibonacciNumbersLessThanN(n));
}
public static int countFibonacciNumbersLessThanN(int n){
if (n <=1){
return 0; // No Fibonacci numbers less than 1
}
int a =1, b =1, count =0;
while (a < n){
count++;
int temp = a + b;
a = b;
b = temp;
}
return count;
}
} in this if input is given as 1 then output should be 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!