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...
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...
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...
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...
Java please. Given a sequence of unsorted numbers, determine how badly out of order they are....
Java please. Given a sequence of unsorted numbers, determine how badly out of order they are. Write a program that, for any given sequence of unique natural numbers, will compute the 'distance' between that original ordering and the same set of numbers sorted in ascending order. The distance should be computed by calculating how far displaced each number is in the original ordering from its correct location in the sorted list and summing those results. For instance, given the list...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two sandwiches based on user input. The sandwich information for both must then print out their details and determine if the two sandwiches are equal. Requirements: Write a class called Bread with the following Instance Variables Name: The name brand of the bread. o   Calories: The number of calories per slice assumed to be between 50 and 250 inclusively....
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per...
Create a Java Program to calculate luggage costs. The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers on a ticket....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT