I am not sure but I think my problem is that my function doesn't compare the char´s right. Am I using the Switch also right?
my input x is a String and when x = "aaaaa" it returns "aaaaa" instead of "zzzzz".
String c = ""; for (int i = 0; i < 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); }
case 'a'.. instead. The decimal value of'a'is not 0. Also use aStringBuilderinstead of+.