Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package RadomDeClase;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CoyDecoDificador {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner teclado = new Scanner(System.in);
  10.        
  11.         System.out.println("Introduce la frase que necesitas codificar");
  12.        
  13.         String palabra = teclado.nextLine();
  14.        
  15.         char[] cadena_char = palabra.toCharArray();
  16.        
  17.         String Codificado = "";
  18.         try {
  19.             for(int i = 0; i <= cadena_char.length; i++)
  20.             {
  21.                
  22.                 int char_ascii = (int)cadena_char[i];
  23.                 //System.out.println(char_ascii);
  24.                
  25.                 if(char_ascii != 32)
  26.                 {
  27.                     char_ascii = char_ascii + 3;
  28.                     if((char_ascii > 90 && char_ascii < 97) || (char_ascii > 122)) { char_ascii = char_ascii - 26;}
  29.                 }
  30.                
  31.                
  32.                
  33.                 char nuevochar = (char)char_ascii;
  34.                
  35.                 Codificado = Codificado + nuevochar;
  36.                
  37.             }
  38.         }
  39.         catch(ArrayIndexOutOfBoundsException aiuube) {}
  40.        
  41.         System.out.println(Codificado);
  42.        
  43.        
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement