Hello Cheggsperts! Couple of Java related questions. AGAIN, PLEASE ANSWER THE FO
ID: 3692381 • Letter: H
Question
Hello Cheggsperts! Couple of Java related questions.
AGAIN, PLEASE ANSWER THE FOLLOWING IN JAVA!!!!! Thank you!
Q1:
Let public static void reverse(Object [] arr) be a method that reverses an array and Person be a class like below:
public class Person {
String name= " ";
public void setName(String name) { this.name = name; } ;
public String getName( ) { return name; } ;
}
The code BELOW is in the main. Draw a box and arrow diagram showing only the final state (after this code is executed) of the people and names array variables and the array elements.
Finally, what is the output of the code?????
Code:
int len = 3;
Person[] people = new Person[len];
String[] names = new String[] {"Peter", "Paul", "Mary"};
Person blank = new Person();
for (int i=0; i<len; i++) {
people[i] = blank;
people[i].setName(names[i]);
}
reverse(people);
for (int i=0; i<len; i++) {
System.out.println(people[i].getName( ) );
}
Q2:
Please write a recursive function void reverse(int [] arr) that reverses an array. e.g. reverse([1,2,3,4]) would change the given array to [4,3,2,1].
What is the stack depth of the recursive function?????
(Hint: write a helper function that does the work).
Explanation / Answer
I couldn't understand your requirement for the first question. Could you explain in detail please. Answer 2:- void reverseArray(int[] x) { if (x != null) { for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.