package edu.westga.secretcode;
import java.util.Scanner;
/**
* Creates the secret code class.
*
* @author Stephen Roland
*
*/
public class SecretCode {
/**
* Perform the ROT13 operation
*
* @param plainText
* the text to encode
* @return the rot13'd encoding of plainText
*/
public static String rotate13(String plainText) {
String cryptText = "";
for (int i = 0; i < plainText.length() - 1; i++) {
char currentChar = plainText.charAt(i);
currentChar += 13;
cryptText.append(currentChar);
}
return cryptText;
}
/**
* Main method of the SecretCode class
*
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (1 > 0) {
System.out.println("Enter plain text to encode, or QUIT to end");
Scanner keyboard = new Scanner(System.in);
String plainText = keyboard.nextLine();
if (plainText.equals("QUIT")) {
break;
}
String cryptText = SecretCode.rotate13(plainText);
String encodedText = SecretCode.rotate13(plainText);
System.out.println("Encoded Text: " + encodedText);
}
}
}
嘿,伙计们,我有个简单的问题。如问题所述,它要求将currentchar附加到crypttext的末尾,将结果保存回crypttext。我所做的是在for循环中这样做,但它不起作用:crypttext.append(currentchar);这似乎很简单,但研究了一个小时后,我卡住了。任何帮助将非常感谢如何做到这一点。提前谢谢。
1条答案
按热度按时间7uzetpgm1#
试试这个,