Created
March 22, 2012 23:11
-
-
Save carlossaraiva/2165364 to your computer and use it in GitHub Desktop.
[ESD} Codificador
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class codificador{ | |
public static void main(String[] args){ | |
Scanner entrada = new Scanner(System.in); | |
System.out.println("Digite a palavra ser codificada:"); | |
String palavra = entrada.next(); | |
int[] palavraChar = new int[palavra.length()]; | |
char auxChar; | |
int auxInt, avanco; | |
System.out.println("Digite o avanço:"); | |
avanco = entrada.nextInt(); | |
for(int i = 0; i < palavra.length(); i++){ | |
auxChar = palavra.charAt(i); | |
auxInt = (int) auxChar; | |
palavraChar[i]= auxInt; | |
} | |
for(int i = 0; i < palavraChar.length; i++){ | |
if(palavraChar[i]+ avanco > 122){ | |
palavraChar[i] =(122 - palavraChar[i]%96) + avanco%26; | |
} | |
else{ | |
palavraChar[i] = palavraChar[i] + avanco ; | |
} | |
System.out.println(palavraChar[i]); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment