Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions