Question: 2. Recursive methods implementation. In the following class named HW2.java, implement 4 methods. I. Given a string, you need to remove all non-letter characters. II.

2. Recursive methods implementation. In the following class named HW2.java,

implement 4 methods.

I. Given a string, you need to remove all non-letter characters.

II. Determine a string is a palindrome or not.

III. Calculate the floor of the log base 2 of an integer n.

IV. Given a series :

You can calculate Pi as Pi=6

2. implement the method to compute S.

package HW2;

public class HW2 {

public static void main( String[] args ) {

String str="a1b1a";

int n=3200;

System.out.println("The original string is: "+str+ " and the new string is:

"+LettersOnly(str));

//verify the first method.

System.out.println("The original string is: "+str+ ". It is palindrome?

"+isPalindrome(str));

//verify the second method.

System.out.println("The floor of the log base 2 of "+n+ " is: "+log2 (n));

//verify the third method.

System.out.println("PI equals "+Math.sqrt(6*Basel(n)));

//verify the fourth method.

}

//method #1

//precondition: none

//postcondition: has returned the string removed all non-letter characters

public static String LettersOnly(String str){

}

//method #2

//precondition: none

//postcondition: has returned true is str is a palindrome otherwise is false

public static boolean isPalindrome(String str){

}

// method #3

// precondition: n >= 1;

// postcondition: The floor of the log base 2 of n has been returned

public static int log2 (int n)

{

}

//1/(1^2)+1/(2^2)+1/(3^2)+...=pi^2/6

// method #4

// precondition: n >= 1;

// postcondition: The sum of series 1/(1^2)+1/(2^2)+1/(3^2)+... is returned

public static double Basel(int n){

}

}

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!