Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PRGString {
- // instance variables - replace the example below with your own
- public static boolean esPrefijo(String a, String b) {
- if (a.equals("")) { return true; }
- if (a.length() > b.length() || !a.equals("") && b.equals("")) { return false; }
- else {
- if (a.charAt(0) == b.charAt(0)) {
- return esPrefijo(a.substring(1, a.length()), b.substring(1, b.length()));
- }
- else return false;
- }
- }
- public static boolean esSubcadena(String a, String b) {
- if (a.equals("")) { return true; }
- if (a.length() > b.length() || !a.equals("") && b.equals("")) { return false; }
- else {
- if (a.charAt(0) == b.charAt(0)) {
- if (esPrefijo(a.substring(1, a.length()), b.substring(1, b.length()))) {return true;}
- else return esSubcadena(a, b.substring(1, b.length()));
- }
- else {
- return esSubcadena(a, b.substring(1, b.length()));
- }
- }
- }
- public static boolean esPalindromoSA(String a) {
- if (a.length() <= 1) { return true; }
- if (!Character.isLetter(a.charAt(0))) {
- return esPalindromoSA(a.substring(1, a.length()));
- }
- if (!Character.isLetter(a.charAt(a.length() -1))) {
- return esPalindromoSA(a.substring(0, a.length()-1));
- }
- if (Character.toUpperCase(a.charAt(0)) == Character.toUpperCase(a.charAt(a.length()-1))) {
- return esPalindromoSA(a.substring(1, a.length()-1));
- }
- else return false;
- }
- public static char miToUpperCase(char a) {
- String ac = "ÀÁÈÉÌÍÒÓÙÚÑ";
- String sinac = "AAEEIIOOUUN";
- char letraEnCurso = Character.toUpperCase(a);
- int pos = ac.indexOf(Character.toUpperCase(letraEnCurso));
- if (pos >= 0) { return sinac.charAt(pos); }
- else return letraEnCurso;
- }
- public static boolean esPalindromo(String a) {
- if (a.length() <= 1) { return true; }
- if (!Character.isLetter(a.charAt(0))) {
- return esPalindromo(a.substring(1, a.length()));
- }
- if (!Character.isLetter(a.charAt(a.length() -1))) {
- return esPalindromo(a.substring(0, a.length()-1));
- }
- if (miToUpperCase(a.charAt(0)) == miToUpperCase(a.charAt(a.length()-1))) {
- return esPalindromo(a.substring(1, a.length()-1));
- }
- else return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment