Computer Applications
Write a program in Java to find the Fibonacci series within a range entered by the user.
Sample Input:
Enter the minimum value: 10
Enter the maximum value: 20
Sample Output:
13
Java
Java Iterative Stmts
13 Likes
Answer
import java.util.Scanner;
public class KboatFibonacciRange
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the minimum value: ");
int m = in.nextInt();
System.out.print("Enter the maximum value: ");
int n = in.nextInt();
int a = 0, b = 1;
while (a <= n) {
if (a >= m)
System.out.println(a);
int c = a + b;
a = b;
b = c;
}
}
}Output

Answered By
3 Likes
Related Questions
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even number