Question: 1 . Considering the recursive parkingLot method, write the fastParkingLot recursive method. public class ParkingLot { public static long parkingLot ( int n ) {

1. Considering the recursive parkingLot method, write the fastParkingLot recursive method.
public class ParkingLot {
public static long parkingLot (int n){
if (n ==1) return 1; // a Civic
else if (n ==2) return 2; // an Explorer or two Civics
else return
parkingLot(n-2)// Explorer in last position
+// or
parkingLot(n-1); // Civic in last position
}
public static void main(String args[]){
System.out.println(parkingLot(4));
}
}
2. Given a string, compute recursively a new string where all the adjacent chars are now separated by
a "*".
allStar("hello")->"h*e*l*l*o"
allStar("abc")->"a*b*c"
allStar("ab")->"a*b"
3. Given the following code below, what is returned for each of the following scenarios.
something("xxre")
something("xxhixx")
something("xhixhix")
public String something(String str){
if (str.equals("")) return str;
if (str.charAt(0)=='x') return something(str.substring(1))+'x';
else return str.charAt(0)+ something(str.substring(1));
}Considering the recursive parkingLot method, write the fastParkingLot recursive method.
public class ParkingLot {
public static long parkingLot (int n){
if (n==1) return 1; // a Civic
else if ) return 2; // an Explorer or two Civics
else return
parkingLot (n-2),?? Explorer in last position
// or
parkingLot (n-1); // Civic in last position
}
public static void main(String args[]){
system.out.println (parkingLot (4));
}
}
Given a string, compute recursively a new string where all the adjacent chars are now separated by
a "*".
allStar("hello") "hIo"
allStar("abc")"ac"
allStar("ab")"a*b"
Given the following code below, what is returned for each of the following scenarios.
something("xxre")
something("xxhixx")
something("xhixhix")
public string something(String str){
if (str.equals("")) return str;
if (str.charAt (0)=='x') return something (str.substring(1))+'x';
else return str.charAt (0)+ something(str.substring(1));
}
 1. Considering the recursive parkingLot method, write the fastParkingLot recursive method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!