Ejecutar cesar
Publicado por Daniel Franco Baena (1 intervención) el 20/11/2016 20:38:22
Hola, he hecho este código para encriptar al método cesar, pero soy nuevo en esto de la programación y no consigo hacer que ejecute en ventana para poder utilizarlo como una aplicación. Agradecería alguna respuesta :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Cesar1 {
private static Scanner s;
public static void main(String[] args){
s = new Scanner(System.in);
String frase1, frase2;
int desplazamiento;
frase2 = "";
String min = "abcdefghijklmnopqrstuvwqyz ";
String may = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
System.out.print("Introdueix el text: ");
frase1 = s.nextLine();
System.out.print("Introdueix la clau : ");
desplazamiento = s.nextInt ();
for(int i = 0; i < frase1.length(); i++){
for(int j = 0; j < min.length(); j++){
if(frase1.charAt(i) == min.charAt(j)){
if(j + desplazamiento >= min.length()){
frase1 += min.charAt((j + desplazamiento) % min.length());
}
else{
frase2 += min.charAt(j + desplazamiento);
}
}
else if (frase1.charAt(i) == may.charAt(j)){
if(j + desplazamiento >= may.length()){
frase2 += may.charAt((j + desplazamiento) % may.length());
}
else{
frase2 += may.charAt(j + desplazamiento);
}
}
}
}
System.out.print(frase2);
}
}
Valora esta pregunta


0