Package handout
Class StringUtility
Object
handout.StringUtility
public class StringUtility
extends Object
This files contains the assignment description for Strings and Exception lab.
Please read this documentation carefully to know the requirement of each
method. This will not compile. Refer to the other file.
-
Constructor Summary
Constructors Constructor Description StringUtility()
-
Method Summary
Modifier and Type Method Description static boolean
isPalindrome(String input)
This method checks whether the given string is a palindrome or not.static char
maxOccuringCharacter(String sentence)
This method takes a sentence and counts the max occurring character.static String
reverse(String sentence)
This method takes in a sentence as a parameter and returns the reverse of the sentence by word.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
StringUtility
public StringUtility()
-
-
Method Details
-
reverse
public static String reverse(String sentence)This method takes in a sentence as a parameter and returns the reverse of the sentence by word. For this particular problem, we will convert all our sentences to lowercase. The result should only return the strings separated by a single space, although the input may contain multiple spaces in between them.
Example:reverse("This is a SENTENCE") will return "sentence is a this". reverse("This SENTENCE") will return "sentence this".
- Parameters:
sentence
- The original sentence to be reversed- Returns:
- Reverse of the given statement
-
maxOccuringCharacter
public static char maxOccuringCharacter(String sentence) throws IllegalArgumentExceptionThis method takes a sentence and counts the max occurring character. It ignores all the spaces, punctuations, digits and converts all the uppercase to lowercase letters. Example:maxOccuringCharacter("iiiiiii") = 'i' maxOccuringCharacter("Iiijjj") = 'i'
- Parameters:
sentence
- The original sentence from which we should find the max occuring character.- Returns:
- The max occuring character. If there are multiple max occuring character return the first character by alphabetical order
- Throws:
IllegalArgumentException
- if the given sentence is empty (length of sentence = 0)
-
isPalindrome
public static boolean isPalindrome(String input)This method checks whether the given string is a palindrome or not. A palindrome is a word, number, phrase, or other sequences of characters that read the same backward as forward, such as madam or racecar. An empty string is considered to be a palindrome.- Parameters:
input
- The string to check- Returns:
- true if the given string is a palindrome and false otherwise
-