Question: PLEASE COMPLETE ALL EXERCISES!!!! AND CLEARLY, LABEL WHICH CODE BELONGS TO WHICH EXERCISE 1.Exercise 6.2.7 2.Exercise 6.2.8 3.Exercise 6.2.9 4.Exercise 6.2.10 The following assignments are




PLEASE COMPLETE ALL EXERCISES!!!! AND CLEARLY, LABEL WHICH CODE BELONGS TO WHICH EXERCISE
1.Exercise 6.2.7
2.Exercise 6.2.8
3.Exercise 6.2.9
4.Exercise 6.2.10
The following assignments are incomplete java codes that should match the assignment instructions given on the right-hand side, please make sure the Java code you post is correct and answers the assignment instructions given.
6.2.7: Print Array Save Submit + Continue RUN CODE TEST CASES ASSIGNMENT DOCS | GRADE | MORE 5 points Status: Not Submitted Write a method that prints the contents of an array. Test this method out on the array created for you in the main method. 1 public class PrintArray 2-{ 3 public static void main(String[] args) 4 - { 5 String[] arr = new String[]{"a", "b", "c"}; 6 printArr(arr); 7 } 8 9 public static void printArr(String[] arr) 10- { 11 // Print everything in the array on its own line 12 13 } 14 } R. 6.2.8: Print Odd Array Indices Save Submit + Continue RUN CODE | TEST CASES ASSIGNMENT DOCS | GRADE MORE 5 points Status: Not Submitted Here we have a program that creates an integer array. Fill in the method printOddIndices to print out just the elements stored at the odd indices of the array 1 public class PrintOdd 2 - { 3 public static void main(String[] args) 4 - { 5 int[] oddIndexArray = new int[] {1, 2, 3, 4, 5}; 6 printOddIndices(oddIndexArray); 7 } 8 9 public static void printOdd Indices(int[] arr) 10 - { 11 // your code goes here! 12 } 13 } For example, the following code: int[] arr = new int[] {10, 20, 30, 40}; printOddIndices(arr); Should print out: 20 40 Because the odd indices in arr are 1 and 3, and index 1 stores the value 20 and index 3 stores the value 40. 6.2.9: Find Index of a String Save Submit + Continue RUN CODE | TEST CASES ASSIGNMENT DOCS | GRADE | MORE 5 points Status: Not Submitted 1 public class MatchingStringTester 2- { 3 public static void main(String[] args) 4 - { 5 System.out.println(MatchingString.findString("Karel")); 6 7 } 8 } In this exercise, you will need to create a static method called findString in the MatchingString class that should iterate over String[] arr looking for the exact match of the String that is passed as a parameter. Return the index of the array where the String is found; if it does not exist in the array, return -1. For example, if the word Karel is passed in, yo method would return 1. 6.2.10: Fibonacci Sequence Save Submit + Continue RUN CODE | TEST CASES ASSIGNMENT DOCS | GRADE MORE 5 points Status: Not Submitted The Fibonacci sequence is the sequence of numbers: O, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called a term. In this exercise, you will need to: 1 public class Fibonacci 2-{ 3 public static void main(String[] args) 4 - { 5 /umber of elements to generate in the sequence int max = 15; 8 9 // create the array to hold the sequence of Fibonacci numbers 10 11 //create the first 2 Fibonacci sequence elements 12 sequence[0] = 0; 13 sequence[1] 1; 14 15 //create the Fibonacci sequence and store it in int[] sequence 16 17 18 //print the Fibonacci sequence numbers 19 20 21 System.out.println(" Index position of 55 is: + findIndex(sequence, 55)); 22 23 } 24 25 // This method finds the index of an element in an array 26 27 public static int findIndex (int[] arr, int n) 28 - { 29 30 // your code goes here 31 } 32 } 1. Create the array int[] sequence that holds the values of the first 15 terms of the Fibonacci sequence. Think carefully about what happens to the index when iterating through the loop to fill this array. Read the Fibonacci description above to help! 2. Then print out the sequence of numbers separated by a space. 3. Finally, create a method findIndex to find the index of the term 55. Sample output: Fibonacci sequence up to 15 terms: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 Index position of 55 is: 10 Hint: You will need to use several loops: One to fill the array, one to print the array, and one to traverse the array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
