Question

In: Computer Science

double_vowels Given a string, return a copy of the string with all of the vowels doubled....

double_vowels

Given a string, return a copy of the string with all of the vowels doubled. Consider the five letters 'aeiou' as vowels.


double_vowels('pencil') → 'peenciil'
double_vowels('xyzzy') → 'xyzzy'
double_vowels('catalog') → 'caataaloog'

middle_hash

Given a string, do three hash marks '###' appear in the middle of the string? To define middle, we'll say that the number of chars to the left and right of the '###' must differ by at most one.


middle_hash('aa###bb') → True
middle_hash('aaa###bb') → True
middle_hash('a###bbb') → False

fence_post

Given two strings, fence and post, return a string made up of count instances of post, separated by instances of fence.

<i>Note</i>: This is an example of the classic "fence post" programming problem. It's a variant of the off-by-one-error (OBOE).


fence_post('X', 'Word', 3) → 'WordXWordXWord'
fence_post('And', 'This', 2) → 'ThisAndThis'
fence_post('And', 'This', 1) → 'This'

balanced_x_y

We'll say that a String is xy-balanced if for all the 'x' chars in the string, there exists a 'y' char somewhere later in the string. So 'xxy' is balanced, but 'xyx' is not. One 'y' can balance multiple 'x's. Return true if the given string is xy-balanced.


balanced_x_y('aaxbby') → True
balanced_x_y('aaxbb') → False
balanced_x_y('yaaxbb') → False

repeated_prefix

Given a string, consider the prefix string made of the first N chars of the string. Does that prefix string appear somewhere else in the string? Assume that the string is not empty and that N is in the range 1..len(str).


repeated_prefix('abXYabc', 1) → True
repeated_prefix('abXYabc', 2) → True
repeated_prefix('abXYabc', 3) → False

Solutions

Expert Solution


Related Solutions

​Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.
Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.(JAVA Code)
(In java) Return a copy of the string with only its first character capitalized. You may...
(In java) Return a copy of the string with only its first character capitalized. You may find the Character.toUpperCase(char c) method helpful NOTE: Each beginning letter of each word should be capitalized. For example, if the user were to input: "United States of America " --> output should be "United States of America" NOT "United states of america" -------------------------------------- (This code is given) public class Class1 { public static String capitalize(String str) {     //add code here } }
34. Write all of the letters that are vowels in the order that they appear in...
34. Write all of the letters that are vowels in the order that they appear in the alphabet including Y. Switch the order of the second and third vowels in the list. Change the fourth and fifth vowels to Y. What does the list of the letters look like now? a. A I E O Y Y b. A I E Y Y c. A I E Y Y Y d. A I E Y 35. He answered the attorney’s...
Writing method in Java Given a string, return the sum of the numbers appearing in the...
Writing method in Java Given a string, return the sum of the numbers appearing in the string, ignoring all other characters. A number is a series of 1 or more digit chars in a row. (Note: Character.isDigit(char) tests if a char is one of the chars '0', '1', .. '9'. Integer.parseInt(string) converts a string to an int.) sumNumbers("abc123xyz") → 123 sumNumbers("aa11b33") → 44 sumNumbers("7 11") → 18
Given the nested collection that maps each term to a set of strings   Return a string...
Given the nested collection that maps each term to a set of strings   Return a string of terms that are repeated in all the nested sets Given : {apple=[apple BALL carrot, ball !carrot! ,!Dog*&]} {apple=[apple BALL carrot, ball !carrot! ,!Dog*&], dog=[ball !carrot! ,!Dog*&]} Return: [ball !carrot! ,!Dog*&] Public static String common(Map<String, Set<Sting>> map) { }
public static java.lang.String removerec(java.lang.String s) Returns a string similar to the given string with all runs...
public static java.lang.String removerec(java.lang.String s) Returns a string similar to the given string with all runs of consecutive, repeated characters removed. For example, given "apple", returns "aple" given "banana", returns "banana" given "baaannannnnaa", returns "banana" given an empty string, returns an empty string Parameters: s - given string Returns: string created from s by removing runs of the same character
string string_long_division (string dividend, string divisor) { string ans; //code in here return ans; } Create...
string string_long_division (string dividend, string divisor) { string ans; //code in here return ans; } Create a function that takes in 2 strings called dividend (is a string because this could be greater than the size of an int) and divisor (is a string because this could be greater than the size of an int) and performs long division on them and returns the result as a string. It would be preferred if the code was written in c++. THIS...
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of...
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of the characters in each ArrayList.  For example, if list1 has strings (“cat, “dog”, “boat”, “elephant”) and list 2 has strings (“bat”, “mat”, “port”, “stigma”), you will return the value 18.  The list 1 has 18 characters in total for all its strings combined and list2 has 16 characters for all of its strings combined.  The higher value is 18. If the character count is the same, you...
write a java program to Translate or Encrypt the given string : (input char is all...
write a java program to Translate or Encrypt the given string : (input char is all in capital letters) { 15 } *) Each character replaced by new character based on its position value in english alphabet. As A is position is 1, and Z is position 26. *) New characters will be formed after skipping the N (position value MOD 10) char forward. A->A+1= B , B->B+2=D ,C->C+3=F, .... Y->Y+(25%10)->Y+5=D A B C D E F G H I...
public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return...
public int getIndexOfWord(String[] arr, String word){ // if found, return the index of word, otherwise return -1 } public boolean areArrays(int[] arr1, int[] arr2){ // 1. initial check: both arrays need to have the same length, return false if not the same // 2. return true if both given arrats are equals(same values in the same indices), false otherwise } public boolean areArraysEqual(String[] arr1, String[] arr2){ // 1. initial check: both arrays need to have the same length, return false...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT