Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Problem3 {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Problem3 run = new Problem3();
  8.         System.out.println(run.shortHand("For I shall love you forever"));
  9.     }
  10.  
  11.     public String shortHand(String input) {
  12.         boolean sh = false;
  13.         boolean single;
  14.         String ans = input;
  15.         String[] split = input.split("\\s");
  16.  
  17.         for (int i = 0; i < split.length; i++) {
  18.             String temp = split[i];
  19.  
  20.             if (temp.length() <= 1) {
  21.                 single = true;
  22.             } else {
  23.                 single = false;
  24.             }
  25.  
  26.             if (temp.equalsIgnoreCase("and")) {
  27.                 String replaced = temp.replace("and", "&");
  28.                 ans = ans + replaced;
  29.                 sh = true;
  30.             } if (temp.equalsIgnoreCase("for")) {
  31.                 String replaced = temp.replace("for", "4");
  32.                 ans = ans + replaced;
  33.                 sh = true;
  34.             } if (temp.equalsIgnoreCase("you")) {
  35.                 String replaced = temp.replace("you", "u");
  36.                 ans = ans + replaced;
  37.                 sh = true;
  38.             } if (temp.equalsIgnoreCase("to")) {
  39.                 String replaced = temp.replace("to", "2");
  40.                 ans = ans + replaced;
  41.                 sh = true;
  42.             }
  43.  
  44.             for (int x = 0; x < ans.length(); x++) {
  45.                 char c = ans.charAt(x);
  46.  
  47.                 if (!single && vowel(c) && !sh) {
  48.                     String front = ans.substring(0, x);
  49.                     String back = ans.substring(x + 1);
  50.                     ans = front + "" + back;
  51.                     System.out.println(ans);
  52.                 }
  53.             }
  54.            
  55.             sh = false;
  56.         }
  57.  
  58.         return ans;
  59.     }
  60.  
  61.     public boolean vowel(char c) {
  62.         if ((c == 'A') || (c == 'a') || (c == 'E') || (c == 'e') || (c == 'I')
  63.                 || (c == 'i') || (c == 'O') || (c == 'o') || (c == 'U')
  64.                 || (c == 'u')) {
  65.             return true;
  66.         } else {
  67.             return false;
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement