Question

JAVA PLEASE: Assignment4A: Fibo-what? If you’ve never heard of the Fibonacci series, it’s an infinite series...

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

Homework Answers

Answer #1

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 -

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … The sequence Fn of Fibonacci numbers is defined by the recurrence relation: Fn = Fn-1 + Fn with seed values F1 = 1 F2 = 1 For more information on...
Please code in Java and please implement constarints Digital Root and Iterations Given a non-negative integer,...
Please code in Java and please implement constarints Digital Root and Iterations Given a non-negative integer, print out its digital root and the number of iterations required to reach it. The digital root is the single digit number obtained by an iterative process of finding the sum of digits. In the next iteration, the sum of the digits in the previous iteration is computed, and the process repeated until a single digit value is obtained. Input Format The first line...
Please Write the whole program in assembly i am able to calculate the fibonacci series but...
Please Write the whole program in assembly i am able to calculate the fibonacci series but not sure how to print it in reverse order. Please give a Complete code !! Programming Exercise 1 (10 points): [call it Ass2-Q1.asm] Write an ASM program that reads an integer number N and then displays the first N values of the Fibonacci number sequence, described by: Fib(0) = 0, Fib(1) = 1, Fib(N) = Fib(N-2) + Fib(N-1) Thus, if the input is N...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
WRITE A JAVA PROGRAM: The last digit of a credit card number is the check digit,...
WRITE A JAVA PROGRAM: The last digit of a credit card number is the check digit, which protects against transaction errors. The following method is used to veryfy credit card numbers. For the simplicity we can assume that the credit card has 8 digits instead of 16. Following steps explains the algorithm in determining if a credit card number is a valid card.  Starting from the right most digit, form the sum of every other digit. For example, if...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
This is in java and you are not allowed to use Java API classes for queues,...
This is in java and you are not allowed to use Java API classes for queues, stacks, arrays, arraylists and linkedlists. You have to write your own implementations for them. You should construct a BST by inserting node values starting with a null tree. You can re-use the code for the insert method given in the sample code from the textbook. -insert method is provided below Your code should have a menu driven user interface at the command line with...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed *...
Using Java. The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display the distance a vehicle has traveled for each hour of a...