Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fibonacci numbers are defined by the sequence: f1 = 1 f2 = 1 fn = fn-1 + fn-2 You need to write a Java program
Fibonacci numbers are defined by the sequence: f1 = 1 f2 = 1 fn = fn-1 + fn-2 You need to write a Java program that prompts the user to enter the value of an integer (n) then checks if n is in the acceptable range. The acceptable range is from 1 to 50. If the user supplies a value out of the valid range, the program MUST reject it and ask the user again to enter a valid value for n. The above check needs to be implemented by a sentinel loop. After receiving a valid value for n, the program will compute the values for all the terms of the Fibonacci series up to and including n then display these values on the screen. Output should be formatted such that each line has five values and each value is displayed left justified in a field width of 15, see the screen shot. Computing the Fibonacci series is simple. The first two terms are predefined and after that any term is the summation of the previous two terms. Sample output is given below in case the user wants the first 50 terms:Please enter a valid number (betveen: 1-50) -15 The number entered-15 is not valid Please enter a valid number (betveen: 1 50) The number entered 55 is not valid Please enter a validnumber (betveen: 1- 50): 50 2 21 233 2584 28657 317811 3524578 39088169 433494437 480752 6976 5 34 377 4181 463 68 514229 5702887 632 5986 01408733 778742049 13 144 1597 8 89 987 10946 121393 13462 69 14930352 165580141 183 6311903 196 18 2178309 24157817 267914296 2971215073 610 6765 75025 832040 9227465 102334155 1134903170 125862 69025
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started