Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code should be in JAVA and USE ONLY RECURSION please do not us any for or while loops to solve these!! here are some

image text in transcribedimage text in transcribed

This code should be in JAVA and USE ONLY RECURSION please do not us any for or while loops to solve these!! here are some test code examples thank you!

System.out.println("Testing out the longestWordLength method ");

String quoteOne =

"Grit, one of the keys to success. The person who perseveres is the one who " +

"will surely win. Success does not come from giving up, it comes from believing " +

"in yourself and continuously working towards the realization of a worthy ideal. " +

"Do not ever give up on what you want most. You know what you truly want. " +

"Believe in your dreams and goals and take daily consistent action in order to " +

"make your dreams a reality.";

System.out.printf("The longest word in the following quote: %s should be 12 -> %d ", quoteOne, longestWordLength(quoteOne));

String quoteTwo = "Try to be like the turtle at ease in your own shell.";

System.out.printf("The longest word in the following quote: %s should be 6 -> %d ", quoteTwo, longestWordLength(quoteTwo));

System.out.println();

System.out.println("Testing the dedupeChars method");

System.out.printf("dedupeChars("a") should be a -> %s ", dedupeChars("a"));

System.out.printf("dedupeChars("aa") should be a -> %s ", dedupeChars("aa"));

System.out.printf("dedupeChars(\"MiSsisSiPpi") should be MiSisiPi -> %s ", dedupeChars("MiSsisSiPpi"));

System.out.printf("dedupeChars("swimMmMming") should be swiming -> %s ", dedupeChars("swimMmMming"));

longestWordLength public static int longestWordLength(String words) Returns length of the longest word in the given String using recursion (no loops). Hint: a Scanner may be helpful for finding word boundaries. After delimiting by space, use the following method on your String to remove punctuation .replaceAll("*a-zA-Z]", ")If you use a Scanner, you will need a helper method to do the recursion on the Scanner object. Parameters: -A String The length of the longest word in the String See Also: Scanner.Scanner (String), Scanner.next, String.split(String), String.replaceAll(String, String),Math.max(int, int)

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

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago