Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1.     private String frase;
  2.  
  3.     public UtilidadesFrase(){
  4.     }
  5.     public UtilidadesFrase(String frase){
  6.         this.frase = frase;
  7.     }
  8.    
  9.     public String palabraSaltoLinea(){
  10.         String fras = frase.replaceAll(" ", "\n");
  11.         return fras;
  12.      }
  13.    
  14.     public boolean palindromo(){
  15.         String fras = frase.replaceAll(" ", "");
  16.         for (int x = 0; x < fras.length(); x++) {
  17.             char chaP = fras.charAt(x);
  18.             char chaF = fras.charAt(fras.length()- (x + 1));
  19.             if(chaP == chaF){
  20.                
  21.  
  22.             }else{
  23.                 x = fras.length();
  24.                 return false;
  25.             }
  26.         }
  27.      return true;  
  28.      } // incompleto
  29.    
  30.     public int cantidadDigitos(){
  31.         int dig = 0;
  32.         for (int z = 0; z < frase.length(); z++){
  33.             char digito = frase.charAt(z);
  34.             if(Character.isDigit(digito) == true){
  35.                 dig = dig +1;
  36.             }
  37.         }
  38.         return dig;
  39.     }
  40.    
  41.     public String fraseReves(){
  42.         String invertida = frase;
  43.         for (int x = invertida.length() - 1; x >= 0; x--) {
  44.             char caracter = invertida.charAt(x);
  45.             System.out.print(caracter);
  46.  
  47.         }
  48.         return "";
  49.     }
  50.    
  51.     public int vecesRepiteCaracter(char caracter){
  52.         int dig = 0;
  53.         for (int x = 0; x < frase.length(); x++){
  54.             char letra = frase.charAt(x);
  55.             if(caracter == letra){
  56.                 dig = dig + 1;
  57.             }
  58.         }    
  59.     return dig;
  60. }
  61.    
  62.    
  63.     public String getFrase() {
  64.         return frase;
  65.     }
  66.  
  67.     public void setFrase(String frase) {
  68.         this.frase = frase.toUpperCase();
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement