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
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
Related Questions
Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]How many times will the following loop execute? Write the output of the code:
int x=10; while (true){ System.out.println(x++ * 2); if(x%3==0) break; }