Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could anyone answer this in java?i will really appreciate! Your program should t

ID: 3761495 • Letter: C

Question

Could anyone answer this in java?i will really appreciate!

Your program should take a string that has been encoded using a "secret" code, and decode it. The code works as follows:

Each letter is decoded using the letter immediately preceding it in the alphabet. "b" becomes "a", "c" becomes "b", etc.

The letter "a" becomes "z".

Each digit is decoded using the preceding digit. "1" becomes "0", "2" becomes "1", etc.

The digit "0" becomes "9".

Characters that are neither letters nor digits are unchanged.

Regardless of whether the input string contains upper- or lowercase characters, the output (one string) should be in all lowercase.

Example:

Explanation / Answer

public class Cipher {

public static void main(String []args) {

char[] ltr = {'a', 'b', 'c', 'c', 'd', 'e','f','g','z,1,4,6,6'};
String str = "This is the alphabet: abcd..........z";
StringBuffer decode = new StringBuffer(str);
// String decode = new String(str);//
char ch;
char repch;
for (int i = 0; i < decode.length(); j++) {    // replace every characted with preceeding character and every digit with preceeding digit
ch = repch = decode.charAt(i);
for (int k = 0; k < ltr.length; k++) {
if (ch == ltr[k]) {
if (k == 0) {
repch = ltr[ltr.length - 1];
} else {
repch = ltr[k - 1];
}
break;
}
}
decode.setCharAt(i, repch);
// System.out.println(str + " -> " + decode);
}
System.out.println(str + " -> " + decode);