Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Problem3 {
- public static void main(String[] args) {
- Problem3 run = new Problem3();
- System.out.println(run.shortHand("For I shall love you forever"));
- }
- public String shortHand(String input) {
- boolean sh = false;
- boolean single;
- String ans = input;
- String[] split = input.split("\\s");
- for (int i = 0; i < split.length; i++) {
- String temp = split[i];
- if (temp.length() <= 1) {
- single = true;
- } else {
- single = false;
- }
- if (temp.equalsIgnoreCase("and")) {
- String replaced = temp.replace("and", "&");
- ans = ans + replaced;
- sh = true;
- } if (temp.equalsIgnoreCase("for")) {
- String replaced = temp.replace("for", "4");
- ans = ans + replaced;
- sh = true;
- } if (temp.equalsIgnoreCase("you")) {
- String replaced = temp.replace("you", "u");
- ans = ans + replaced;
- sh = true;
- } if (temp.equalsIgnoreCase("to")) {
- String replaced = temp.replace("to", "2");
- ans = ans + replaced;
- sh = true;
- }
- for (int x = 0; x < ans.length(); x++) {
- char c = ans.charAt(x);
- if (!single && vowel(c) && !sh) {
- String front = ans.substring(0, x);
- String back = ans.substring(x + 1);
- ans = front + "" + back;
- System.out.println(ans);
- }
- }
- sh = false;
- }
- return ans;
- }
- public boolean vowel(char c) {
- if ((c == 'A') || (c == 'a') || (c == 'E') || (c == 'e') || (c == 'I')
- || (c == 'i') || (c == 'O') || (c == 'o') || (c == 'U')
- || (c == 'u')) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement