Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please implement a java program below with these 3 different function of recusive method. Thanks Write a recursive method that returns true if the String

Please implement a java program below with these 3 different function of recusive method. Thanks

Write a recursive method that returns true if the String contains the char, otherwise returns false.

public boolean recursiveContains(char c, String s){

// Implement body

}

Write a recursive method that returns true if all the characters in the String are identical, otherwise false. If the String is empty, all the characters are identical.

public boolean recursiveAllCharactersSame(String s){

// Implement body

}

Write a recursive method that returns the number of characters in the String, which may be 0.

public int recursiveCount(char c, String s){

// Implement body

--------------------------------------------------------------------------------------

public class Recursive{

public static double powerN(double x, int n){ if(n==0) { return 1; } else if(n==1) { return x; } else return x*powerN(x,n-1);

}

public static double harmonicSum(int n){ if(n==0) { return 0; } else { return ((double)1/n)+harmonicSum(n-1); } }

public static void reverseDisplay(int value){ if (value <= 0) return;

System.out.print(value % 10); reverseDisplay(value / 10); }

public static void reverseDisplay(String value){ if (value.length() == 0) return; System.out.print(value.substring(value.length() - 1)); reverseDisplay(value.substring(0, value.length()-1)); }

public static void main(String[] args) { double m; m = powerN(15,3); System.out.println(m); System.out.println(harmonicSum(1992)); reverseDisplay(123456789); System.out.println(); reverseDisplay("Norin Chea"); }

}

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

3. List ways to manage relationship dynamics

Answered: 1 week ago

Question

How do we organise for international logistics?

Answered: 1 week ago