Advertisement
Shavit

P. 100 Ex. 11.18

Feb 23rd, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. public class StringClass
  5. {
  6.     public boolean isPalindrom(String input)
  7.     {
  8.         boolean isPalindrom = true;
  9.         for(int i = 0; i < (input.length() / 2); i++)
  10.         {
  11.             if(input.charAt(i) != input.charAt(input.length() - i))
  12.                 isPalindrom = false;
  13.         }
  14.         return isPalindrom;
  15.     }
  16.     public char mostCommon(String input)
  17.     {
  18.         char mostCommon = '\0';
  19.         int length = input.length();
  20.         int currentCounter;
  21.         int max = 0;
  22.        
  23.         for(int i = 0; i < length; i++)
  24.         {
  25.             currentCounter = 0;
  26.             for(int j = 0; j < length; j++)
  27.             {
  28.                 if(input.charAt(i) == input.charAt(j))
  29.                     currentCounter++;
  30.             }
  31.             if(currentCounter > max)
  32.             {
  33.                 mostCommon = input.charAt(i);
  34.                 max = currentCounter;
  35.             }
  36.         }
  37.         return mostCommon;
  38.     }
  39.     public String reverted(String input)
  40.     {
  41.         String reverted = "";
  42.         for(int i = input.length() - 1; i >= 0; i++)
  43.         {
  44.             reverted += input.charAt(i);
  45.         }
  46.         return reverted;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement