Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java In the following exercises, write the methods and code to test them. 1. Write a method that takes a string as a parameter and

java image text in transcribed
image text in transcribed
In the following exercises, write the methods and code to test them. 1. Write a method that takes a string as a parameter and prints each of the characters in the string followed by a space in the same order they appear in the string public static void strChars (String s) Calling strChars (**will print "", (the empty string) Calling strChars ("abc") will print "a b c 2. Write a method that takes two strings sub and str as parameters. The method will return true if the first string is a substring of the second one, false otherwise. public static boolean isSubstring(String sub, String str) Calling isSubstring("arc", "Antarctica") will return true Calling is Substring("comic", "comedian") will return false 3. Write a method delete that takes two strings, str and substr, as parameters. The method will return a string which includes each character in str but has the first occurrence of substr deleted. public static String delete (String str, String substr) Calling delete ("Labyrinthine", "in") will return "Labyrthine" 4. Write a method that takes one string as a parameter and returns a string with each letter duplicated. Letters will appear in the same order as in the parameter. public static String duplicate (String s) Calling duplicate ("Mango") will return the string "Maannggoo 5. Write a method to change the name format from clastName>, to sfirstName> public static String name (String s) Calling name ("Siddiqi, Wafa") will return "Wafa Siddiqi". 6. Write a method to check if a word is a palindrome. A palindrome is a word that spells the same forward and backward. For example "dad", "civic" and "radar". public static boolean ispalindrome (String str) Calling is Palindrome ("rotator") will return true. Calling is Palindrome ("Baba") will return false Test your program with the words: malayalam, hannah, rotator, repaper and any other non-palindrome words. 7. Write a method that takes a string, str, as a parameter and returns an array of strings. The elements of the array are one character strings which are listed in the same order that they appear in str. public static String[] characters (String str) Calling characters ("red hat") will return the string array: 8. Write a method that returns the common prefix for two strings. If the strings don't have a common prefix, the method will return the empty string. Test the method by reading two string and display the common prefix if it is not the empty string or a message indicating that the two words do not have a common prefix public static String prefix (String stri, String str2) Calling prefix("distance", "disappoint") will return "dis" 9. White spaces characters are the space,',the new line, " ', and the tab, '\t'. Write a method to count the number of white spaces in a string. Write an application to test the method. public static int countWhiteSpaces (String s) Calling countWhiteSpaces ("Hope is a walking dream") will return 4. 10. Write a method to count number of words in a given string. Assume that a string contains at least one word and words are separated by one space. The string does not have leading or trailing spaces. public static int wordsCount(String s) for example calling wordsCount("The obstacle is the path") will return 5. 11. Modify Question 10 to write a method that counts the number of words in a string. The string might include leading and trailing spaces and the words may be separated by any number of white spaces

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

Demonstrates a real belief and passion for change.

Answered: 1 week ago