Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GroupProject
- {
- public static char[] stringToChar(String word)
- {
- char[] allLetters = word.toCharArray();
- return allLetters;
- }
- public static int countLettersInString(String word)
- {
- word = word.replaceAll(" ", "");
- int counter = word.length();
- return counter;
- }
- public static String weHateTheLetterE(String word)
- {
- word = word.replaceAll("e", "");
- word = word.replaceAll("E", "");
- return word;
- }
- public static String weLoveTheLetterS(String word)
- {
- word = word.replaceAll(" ", "S");
- return word;
- }
- public static int pIndexAdder(String word)
- {
- int total = 0;
- char[] letters = word.toCharArray();
- for (int i = 0; i < word.length(); i++)
- {
- if (letters[i] == 'p' || letters[i] == 'P')
- {
- total = total + i;
- }
- }
- return total;
- }
- public static void main(String[] args)
- {
- // pass "I love java programming" to the stringToChar method and print//
- // the returned array// Define String Variable
- // Q1
- System.out.print("Q1: ");
- String testToChar = "I love java programming";
- char[] stringArray = stringToChar(testToChar);
- for (int i = 0; i < stringArray.length; i++)
- {
- System.out.println(stringArray[i]);
- }
- // Q2
- String testToLetter = "I love java programming";
- System.out.println("Q2: " + countLettersInString(testToLetter));
- // Q3
- String TheLetterE = "If only the letter E didn't exist - I'd be ecstatic";
- System.out.println("Q3: " + weHateTheLetterE(TheLetterE));
- // Q4
- String LoveS = "I'd love it if every sentence that contained the letter s where the spaces are supposed to be";
- System.out.println("Q4: " + weLoveTheLetterS(LoveS));
- // Q5
- String CountP = "P is Pretty Well Pindexed Pin This P Strong String";
- System.out.println("Q5: Amount of P's in String: "+pIndexAdder(CountP));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment