Menu
Question Index
...


Write a program to find the nearest Fibonacci number. The Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc.,. Assume that the input number will be always greater than 3. There is no upper limit to the input number.

Input (Integer) Output (Integer)
9 8 (9 is between 8 and 13 and is nearer to 8 than 13)
29 34 (29 is between 21 and 34 and is nearer to 29 than 34)
50 55 (50 is between 34 and 55 and is nearer to 55 than 34)

class FindNearestFibonacciNumber

{    public static void main(String s[])
    {
        int input = 245;
        int result = findNearestFibonacciNumber(input);
        
        System.out.println("The nearest Fibonacci number for " + input + " is " + result);

    }


public static int findNearestFibonacciNumber(int input)
{
//Write code here to find the nearest Fibonacci number to the given input and return the same.
}
}

Doubts

Problems

Topic: for Loop In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App