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
11 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
Convert the following for loop segment to an exit-controlled loop.
for (int x = 1, y = 2; x < 11; x += 2, y += 2) { System.out.println(x + "\t" + y); }
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 numberDefine 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:
for(int j = 12; j >= 2; j -= 2) { if(j % 5 == 0) continue; System.out.println(j); }