rsvaco

prg pract 1 2017

Mar 1st, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. public class PRGString {
  2.     // instance variables - replace the example below with your own
  3.     public static boolean esPrefijo(String a, String b) {
  4.         if (a.equals("")) { return true; }
  5.         if (a.length() > b.length() || !a.equals("") && b.equals("")) { return false; }          
  6.         else {
  7.             if (a.charAt(0) == b.charAt(0)) {
  8.                 return esPrefijo(a.substring(1, a.length()), b.substring(1, b.length()));
  9.             }
  10.             else return false;        
  11.         }
  12.     }
  13.    
  14.    
  15.     public static boolean esSubcadena(String a, String b) {
  16.         if (a.equals("")) { return true; }
  17.         if (a.length() > b.length() || !a.equals("") && b.equals("")) { return false; }
  18.         else {
  19.             if (a.charAt(0) == b.charAt(0)) {
  20.                 if (esPrefijo(a.substring(1, a.length()), b.substring(1, b.length()))) {return true;}
  21.                 else return esSubcadena(a, b.substring(1, b.length()));
  22.             }
  23.             else {
  24.                 return esSubcadena(a, b.substring(1, b.length()));
  25.             }
  26.         }
  27.     }
  28.    
  29.    
  30.     public static boolean esPalindromoSA(String a) {
  31.         if (a.length() <= 1) { return true; }
  32.         if (!Character.isLetter(a.charAt(0))) {
  33.             return esPalindromoSA(a.substring(1, a.length()));
  34.         }
  35.         if (!Character.isLetter(a.charAt(a.length() -1))) {
  36.             return esPalindromoSA(a.substring(0, a.length()-1));
  37.         }
  38.         if (Character.toUpperCase(a.charAt(0)) == Character.toUpperCase(a.charAt(a.length()-1))) {
  39.             return esPalindromoSA(a.substring(1, a.length()-1));
  40.         }
  41.         else return false;
  42.     }
  43.    
  44.    
  45.     public static char miToUpperCase(char a) {
  46.         String ac = "ÀÁÈÉÌÍÒÓÙÚÑ";
  47.         String sinac = "AAEEIIOOUUN";
  48.         char letraEnCurso = Character.toUpperCase(a);
  49.         int pos = ac.indexOf(Character.toUpperCase(letraEnCurso));
  50.         if (pos >= 0) { return sinac.charAt(pos); }
  51.         else return letraEnCurso;
  52.     }
  53.    
  54.    
  55.         public static boolean esPalindromo(String a) {
  56.         if (a.length() <= 1) { return true; }
  57.         if (!Character.isLetter(a.charAt(0))) {
  58.             return esPalindromo(a.substring(1, a.length()));
  59.         }
  60.         if (!Character.isLetter(a.charAt(a.length() -1))) {
  61.             return esPalindromo(a.substring(0, a.length()-1));
  62.         }
  63.         if (miToUpperCase(a.charAt(0)) == miToUpperCase(a.charAt(a.length()-1))) {
  64.             return esPalindromo(a.substring(1, a.length()-1));
  65.         }
  66.         else return false;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment