Write a program called Caesar.java that will decode a message that has been \"sh
ID: 440901 • Letter: W
Question
Write a program called Caesar.java that will decode a message that has been "shifted" (or moved over) by three characters. One nice trick is because a char in Java is actually represented as a number, and there are more characters available than just those in the alphabet, we don't have to worry about wrapping around from C back to Z, etc. Also because we don't know loops (yet :-) ), you can assume that the message is a precise length, as seen below. Write code that will decipher this phrase that was, in fact, an actual message of Caesar's in 49 BC (well, as best as we know, at least). And remember - it's in Latin... INPUT: A fixed-length set of 12 characters as a String, such as DOHDLDFWDHVW OUTPUT: "The decoded phrase is: " + resultExplanation / Answer
public class Decode {
public static void main(String args[]) {
String cipherText = args[0];
String plainText = "";
for(int i= 0; i <cipherText.length(); i++) {
int j = (i+3) % cipherText.length();
plainText += cipherText.charAt(j);
}
System.out.println("he decoded phrase is: "+plainText);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.