JAVA PLEASE:
Assignment4A: Fibo-what? If you’ve never heard of the Fibonacci series, it’s an infinite series that occurs everywhere in nature. It starts off with two digits – 0 and 1. To get the next value in the series, you add the previous two values. In this case, the third value is 0+1 = 1. The fourth value is 1+1 = 2, the fifth 1+2=3 and so on, to give us a series like: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,… I always wondered what it would look like if you changed the starting values from 0 and 1 to some arbitrary (and if it would matter). We’re going to do that here. Ask the user for a pair of starting values as well as a number of times to iterate the series, then produce the correct output. We recommend you use a FOR loop and use a sum variable. For part 1 of this assignment, design pseudocode to solve this problem. When working on the source code, call the file name Assignment4A(.java, .cs, .cpp) and the class name Assignment4A. When printing the next value in the series, print the comma first. The first two values are special cases for printing. Sample Output #1: Enter seed 1: 5 Enter seed 2: 8 Number of iterations: 10 5,8,13,21,34,55,89,144,233,377,610,987 Sample Output #2: Enter seed 1: 56 Enter seed 2: 78 Number of iterations: 6 56,78,134,212,346,558,904,1462
Solution : Code below for fibonacci numbers between two seeds in java. Class name is 'Assignment4A' -(attached the sample output image after the image)
import java.util.*;
public class Assignment4A
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter seed 1: ");
int firstSeed =sc.nextInt();
System.out.print("Enter seed 2: ");
int secondSeed=sc.nextInt();
System.out.print("Number of iterations: ");
int n=sc.nextInt();
System.out.print("\n");
for (int i = 1; i <= n+2; ++i)
{
if(i==n+2)
{
System.out.print(firstSeed );
break;
}
System.out.print(firstSeed + " , ");
int sum = firstSeed + secondSeed;
firstSeed = secondSeed;
secondSeed = sum;
}
}
}
Sample output image - 1 :
Sample output image-2 :
Code image -
Get Answers For Free
Most questions answered within 1 hours.