import java.util.StringTokenizer; public class StringOperations{ /** * wordCount counts the number of words in a string * @param str The string to count * @return The number of words */ public static...

import java.util.StringTokenizer;
public class StringOperations{ /** * wordCount counts the number of words in a string * @param str The string to count * @return The number of words */ public static int wordsCount (String str) { StringTokenizer strTok = new StringTokenizer(str); return strTok.countTokens();

}

/** * Convert string to array * * @param array The array to be converted as char array * @return A reference to the String */ public static String arrayToString(char [] array) { String newString = String.valueOf(array); return newString; } /** * The mostFrequent method finds the characters that shows the most * in a string * * @param str The string to check * @return the character that appears the most */ public static char mostFrequent(String str) { //convert the string to characters char [] cArray =str.toCharArray(); //create an int array to hold the frequencies of the characters int [] frequencies = new int[cArray.length]; //intialize the frequency array for (int i = 0; i frequencies[mostFrequent]) mostFrequent=i; } //return the most frequent character return cArray[mostFrequent]; } /** * The replacementSubString takes three Strings as args returning one * string wiht the ocurrance of the second string gone replaced by the * third string. * @param string1 The first string * @param string2 Second string * @param string3 Third string * @return The resultant string */ public static String replaceString(String string1, String string2, String string3) { //make sure string2 and string are different if (string2.equals(string3)) return string1; //make a StringBuffer object for string1 StringBuffer strbuff= new StringBuffer(string1); //find the first ocurrance of string3 int index = strbuff.indexOf(string2); while(index != -1) { //replace the substring strbuff.replace(index,(index + string2.length(),string3()); //find the next time it shows index = strbuff.indexOf(string2); } //return the string return strbuff.toString(); }}
What is wrong?
May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here