java - My 'decrypt' code doesn't work correctly -
i not sure think problem function doesn't compare char´s right. using switch right?
my input x string , when x = "aaaaa" returns "aaaaa" instead of "zzzzz".
string c = ""; (int = 0; < x.length(); i++) { char getchar = x.charat(i); switch (getchar) { case 1: (getchar) = 'a'; c += "z"; break; case 2: (getchar) = 'b'; c += "y"; break; case 3: (getchar) = 'c'; c += "x"; break; case 4: (getchar) = 'd'; c += "w"; break; case 5: (getchar) = 'e'; c += "v"; break; case 6: (getchar) = 'f'; c += "u"; break; case 7: (getchar) = 'g'; c += "t"; break; case 8: (getchar) = 'h'; c += "s"; break; case 9: (getchar) = 'i'; c += "r"; break; case 10:(getchar) = 'j'; c += "q"; break; case 11:(getchar) = 'k'; c+= "p"; break; case 12:(getchar) = 'l'; c += "o"; break; case 13:(getchar) = 'm'; c += "n"; break; default : c += x.charat(i); } } system.out.println(c); } switch (getchar)//<--you passing charcter in switch case //but checking 1,2 int case 1,2...
what need alter case
as in switch passing characters a,b,c...
switch(getchar) { case 'a': //yourwork break; //do letters } note
moreover concacting string should utilize stringbuilder (as maroun maroun) has suggested , utilize stringbuilder.append('char') method add together character string builder straight no need utilize string (i.e "a","b" etc.).
java
No comments:
Post a Comment