Fórum Array de caracteres. #568575
09/04/2009
0
public class Crip {
public static char recebe, devolve;
public static char senha;
public static char [] caracteres = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'y',x', 'z' };// aqui esta o meu problema.
public static char getRecebe(char recebe) {
for (int op = 0; op < caracteres.length; op++) {
char compara;
compara = caracteres[op];
if (recebe == compara) {
int resposta;
resposta = op + 3;
recebe = caracteres[resposta];
break;
}// fim if
}// fim for
return recebe;
}// fim getRecebe
public static char getDevolve(char devolve) {
for (int op = 0; op < caracteres.length; op++) {
char compara;
compara = caracteres[op];
if (devolve == compara) {
int resposta;
resposta = op - 3;
devolve = caracteres[resposta];
break;
}// fim if
}// fim for
return devolve;
}// getDevolve
[color=red][/color][color=#444444][/color]Flavio Pio
Curtir tópico
+ 0Posts
09/04/2009
Vagner Planello
Gostei + 0
09/04/2009
Flavio Pio
Gostei + 0
09/04/2009
Regis Fleck
public static char [] caracteres = new char[]
{
'a', 'b', 'c',
'd', 'e', 'f',
'j', 'k', 'l',
'm', 'n', 'o',
'p', 'q', 'r',
's', 't', 'u',
'v', 'w', 'y',
x', 'z' }; // aqui esta o meu problema.
Gostei + 0
09/04/2009
Junhu
Gostei + 0
09/04/2009
Carlos Heuberger
char ch;
...
char resposta = ch + 3; // ou ch - 3
if (resposta > 'z')
ch = ch - 'z' - 1 + 'a';// ajuste
char[] arr = new char['a'-'z'+1]; // ou 26
for (char ch = 'a'; ch <= 'z'; ch++)
arr[ch-'a'] = ch;
Gostei + 0