The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, for example: 0, 1, 1, 2, 3, 5, 8, 13. Complete the fibonacci() method, which takes in an index, n, and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7 the output is: fibonacci (7) is 13 Note: Use recursion and DO NOT use any loops. 484924.3417574.qx3zay7 LAB ACTIVITY HEERENS VOSAWNE 1 import java.util.Scanner; 3 public class LabProgram { 2 5 9 10 11 12 13 8.10.1: LAB: Fibonacci sequence (recursion) 16 17 public static int fibonacci(int n) { /* Type your code here. */ } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int startNum; 14 15 } startNum scnr.nextInt (); 18 System.out.println("fibonacci(" + startNum + ") is + fibonacci(startNum)); Develop mode Submit mode LabProgram.java Enter program input (optional) If your code requires input values, provide them here. 0/10 Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. 8.11 LAB: All permutations of names Write a program that lists all ways people can line up for a photo (all permutations of a list of Strings). The program will read a list of one word names into ArrayList name List (until -1), and use a recursive method to create and output all possible orderings of those names separated by a comma, one ordering per line. When the input is: Julia Lucas Mia -1 then the output is (must match the below ordering): Julia, Lucas, Mia Julia, Mia, Lucas Lucas, Julia, Mia Lucas, Mia, Julia Mia, Julia, Lucas Mia, Lucas, Julia 484924 3417574.qx3y7 LAB ACTIVITY 4 public class PhotoLineups { 5 6 7 8 9 10 11 12 13 14 15 16 17 18 8.11.1: LAB: All permutations of names 19} 20 } // TODO: Write method to create and output all permutations of the list of names. public static void printAllPermutations (ArrayList<String> permList, ArrayList<String> nameList) { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> nameList = new ArrayList<String>(); ArrayList<String> permList = new ArrayList<String>(); String name; Develop mode Submit mode PhotoLineups.java // TODO: Read a list of names into nameList; stop when -1 is read. Then call recursive method. } Enter program input (optional) If your code requires input values, provide them here. Run program Program output displayed here Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Input (from above) →→→→ PhotoLineups.java (Your program) 0/10 Output (shown below) The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, for example: 0, 1, 1, 2, 3, 5, 8, 13. Complete the fibonacci() method, which takes in an index, n, and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7 the output is: fibonacci (7) is 13 Note: Use recursion and DO NOT use any loops. 484924.3417574.qx3zay7 LAB ACTIVITY HEERENS VOSAWNE 1 import java.util.Scanner; 3 public class LabProgram { 2 5 9 10 11 12 13 8.10.1: LAB: Fibonacci sequence (recursion) 16 17 public static int fibonacci(int n) { /* Type your code here. */ } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int startNum; 14 15 } startNum scnr.nextInt (); 18 System.out.println("fibonacci(" + startNum + ") is + fibonacci(startNum)); Develop mode Submit mode LabProgram.java Enter program input (optional) If your code requires input values, provide them here. 0/10 Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. 8.11 LAB: All permutations of names Write a program that lists all ways people can line up for a photo (all permutations of a list of Strings). The program will read a list of one word names into ArrayList name List (until -1), and use a recursive method to create and output all possible orderings of those names separated by a comma, one ordering per line. When the input is: Julia Lucas Mia -1 then the output is (must match the below ordering): Julia, Lucas, Mia Julia, Mia, Lucas Lucas, Julia, Mia Lucas, Mia, Julia Mia, Julia, Lucas Mia, Lucas, Julia 484924 3417574.qx3y7 LAB ACTIVITY 4 public class PhotoLineups { 5 6 7 8 9 10 11 12 13 14 15 16 17 18 8.11.1: LAB: All permutations of names 19} 20 } // TODO: Write method to create and output all permutations of the list of names. public static void printAllPermutations (ArrayList<String> permList, ArrayList<String> nameList) { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> nameList = new ArrayList<String>(); ArrayList<String> permList = new ArrayList<String>(); String name; Develop mode Submit mode PhotoLineups.java // TODO: Read a list of names into nameList; stop when -1 is read. Then call recursive method. } Enter program input (optional) If your code requires input values, provide them here. Run program Program output displayed here Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Input (from above) →→→→ PhotoLineups.java (Your program) 0/10 Output (shown below)
Expert Answer:
Related Book For
Vector Mechanics for Engineers Statics and Dynamics
ISBN: 978-0073398242
11th edition
Authors: Ferdinand Beer, E. Russell Johnston Jr., David Mazurek, Phillip Cornwell, Brian Self
Posted Date:
Students also viewed these programming questions
-
It is very common in science and engineering to work with large data sets (large sets of numbers which are stored in a data file), which represent particular measurements in an experiment. We...
-
Carol Harris, Ph.D, CPA, is a single taxpayer and she lives at 674 Yankee Street, Durham, NC 27409. Her Social Security number is 793-52-4335. Carol is an Associate Professor of Accounting at a local...
-
The treasury strips maturing in 1, 2, 3, and and 5 years had the following price as of today: 1 year Treasury strip = $950 2 year Treasury strip = $950 3 year Treasury strip = $950 5 year Treasury...
-
Which type of Organizational Model put the MOST emphasis on establishing MORALE and AUTONOMY O a. Hierarchical style Model b. O c. O d. Flat Management (Holocracy) Model Multi-divisional style Model...
-
Calculate the frequency, energy (in keV), and wavelength of the K" x ray for the elements (a) Calcium (Ca, Z = 20); (b) Cobalt (Co, Z = 27); (c) Cadmium (Cd Z = 48).
-
In the solution to the advertising selection model in Example 7.6, we indicated that the women 36 to 55 group is a bottleneck in the sense that the company needs to spend a lot more than it would...
-
Consider the methanol oxidation data in Table B.20. Perform a thorough analysis of these data. What conclusions do you draw from this analysis? x x2 3 X4 Xs y 0 454 8.8 3.90 1.30 1.1 0 474 8.2 3.68...
-
In a statement to Gillettes shareholders, Chairman and CEO James Kilts indicated, Despite several new product launches, Gillettes advertising-to-sales declined dramatically . . . to 6.5 percent last...
-
A company produces and sells a single product. The standard cost card for that product follows: Direct Materials Standard Quantity 2 feet Standard Price/Rate Direct Labor Variable Overhead Fixed...
-
A beginning accounting student tried to complete a work sheet for Joyce Lee's Tax Service. The following adjusting entries were to have been analyzed and entered onto the work sheet. The work sheet...
-
A and B formed a partnership on December 31, 2020. A contributed $60,000 cash. B's investment consisted of cash, $8,000; inventory, $24,000; and supplies, $8,000 - all at fair market values. Profit...
-
What is the role of a medical guardian? Why did the court appoint a medical guardian for the child?
-
Paul was trying to sell his accounting practice together with the office building from which it operated. Janine was interested in purchasing as she wanted to work closer to home and she liked the...
-
Explain global economic integration and give examples. Contrast international strategies for entering foreign markets versus domestic markets. Explain deeply with proper real life example
-
You are a commercial real estate broker in New York City and you are slowly, but surely making a name for yourself among the most successful companies in the region. One of your clients, a developer...
-
Analyze tariffs and other trade barriers. Discuss determinants of foreign exchange rates. Identify firms' strategic responses to deal with foreign exchange movements.
-
An ethical dilemma refers to a situation where you must: treat someone unfairly. choose between equally unsatisfactory alternatives. choose between a correct and an incorrect option balance the...
-
Create an appropriate display of the navel data collected in Exercise 25 of Section 3.1. Discuss any special properties of this distribution. Exercise 25 The navel ratio is defined to be a persons...
-
The wheels attached to the ends of rod AB roll along the surfaces shown. Using the method of Section 15.4 B and knowing that the acceleration of wheel B is zero, derive an expression for the angular...
-
The roller-coaster track shown is contained in a vertical plane. The portion of track between A and B is straight and horizontal, while the portions to the left of A and to the right of B have radii...
-
A space vehicle is in a circular orbit of 2200-km radius around the moon. To transfer it to a smaller circular orbit of 2080-km radius, the vehicle is first placed on an elliptic path AB by reducing...
-
Approximately 50,000 new titles, including new editions, are published each year in the United States, giving rise to a $25 billion industry in 2001. In terms of percentage of sales, this industry...
-
When you think of political persuasion, you may think of the effortsthat political campaigns undertake to persuade you that their candidate is betterthan the other candidate. In truth, campaigns are...
-
In late 2013, the taxi company Yourcabs.com in Bangalore, India, was facing a problem with the drivers using their platformnot all drivers were showing up for their scheduled calls. Drivers would...
Study smarter with the SolutionInn App