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...
-
The sales and cash receipts journals of Caverly Office Products include the following entries: Identify the missing information in the cash receipts journal for those transactions listed. All credit...
-
It has been suggested that limits be put on the dose in vitamin A supplements sold in stores. What is a possible reason for this limitation?
-
In the Kessler International Survey, what was the major motivation for employee fraud? a. Greed b. Need c. Vindictiveness d. Lack of internal controls e. None of the above
-
Home Products Company manufactures a complete line of kitchen glassware. The Beverage Division specializes in 12-ounce drinking glasses. Erin Fisher, the superintendent of the Beverage Division,...
-
Financial reporting theory. Homework: Week #1 ... < Question 2, E1-3 (book/s... HW Score: 25%, 1 of 4 points O Points: 0 of 1 Save Vikram Patel, one of your friends from high school who is a financ...
-
The following table summarizes the operating results for Bene Petits first year of operations: Bene Petit First year operating data: Single (1 serving) Dual (2 servings) Family (4 servings) Total...
-
We asked a randomly selected group of customers to rate their shopping experience at a local department store on a scale of 10 100. The distribution we obtained can be written as: Ratings N (75,...
-
What part should the sales function play when drawing up a detailed 12 months operational marketing plan for EMA?
-
Hardware controls relate to access to computer equipment. Do you agree? Why or why not?
-
Discuss the role of psychological testing in the selection process for salespeople.
-
Differentiate between production, sales and marketing orientation.
-
How important are sales transactions in the typical audit engagement?
-
The price of a European put that expires in six months and has a strike price of $100 is $3.59. The underlying stock price is $102, and a dividend of $1.50 is expected in four months. The term...
-
For the following exercises, find the inverse of the function and graph both the function and its inverse. f(x) = 4 x 2 , x 0
-
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...
-
Initially, a 200-gallon tank is filled with pure water. At time \(t=0\), a salt concentration with 3 pounds of salt per gallon is added to the container at the rate of 4 gallons per minute, and the...
-
You make 2 quarts of salsa for a party. The recipe calls for 5 teaspoons of lime juice per quart, but you had accidentally put in 5 tablespoons per quart. You decide to feed your guests the salsa...
-
Consider the epidemic model leading to the system in Expression (3.153). Choose the constants as \(a=2.0\) days \(^{-1}, d=3.0\) days \(^{-1}\), and \(r=1.0\) day \(^{-1}\). What are the eigenvalues...
Study smarter with the SolutionInn App