Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Provides some methods to manipulate text
- *
- * @author Tirth Patel
- */
- public class LoopyText
- {
- private String text;
- /**
- * Creates a LoopyText object with the given text
- * @param theText the text for this LoopyText
- */
- public LoopyText(String theText)
- {
- text = theText;
- }
- /**
- * Gets every second character of the string
- * @return the second character
- */
- public String getEverySecondCharacter()
- {
- String secondChar="";
- for(int i=0; i<text.length()/2; i++)
- {
- secondChar = secondChar + text.charAt(i*2+1);
- }
- return secondChar;
- }
- /**
- * Gets the number of uppercase letters in the text
- * @return the number of uppercase letters
- */
- public int upperCaseCount()
- {
- int caseCount=0;
- for (int i=0; i<text.length(); i++)
- {
- if(Character.isUpperCase(text.charAt(i)))
- {
- caseCount++;
- }
- }
- return caseCount;
- }
- /**
- * Returns a string consisting of the first character of each word
- * @return the first character
- */
- public String firstLetters()
- {
- String firstChar = "";
- for (String space : text.split(" "))
- {
- firstChar = firstChar + space.charAt(0);
- }
- return firstChar;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement