The program allows the user to enter a phrase and converts it to ROT13, where each English letter entered, becomes the letter 13 places after it(A becomes N). My current code works when 1 character is entered, however I need it to run through the code the number of times there are characters. I've tried to put in a while loop at the beginning, but it doesn't seem to be working. Why is this?
import java.io.*;
public class J4_1_EncryptionErasetestCNewTry
{
public static void main (String [] args) throws IOException
{
BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));// Buffered Reader reads the number inputed
String key [] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String keyA [] = {"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M"};
System.out.println("Enter a phrase: ");
String phrase = myInput.readLine();
int length = phrase.length();
int y = 0, i = 0, num = 0;
while (y <= length) {
String letter = Character.toString(phrase.charAt(y));
y++;
while(!(letter.equals(key[i]))){
i++;
}
num = i;
System.out.println(keyA[num]);
y++;
}
}
}
y++twice within the same loop? Indenting would really help, as would explaining what "doesn't work" (including sample input/output). Also, given that A-Z are sequential characters (and have sequential numeric values), can you think of a way to implement ROT-n without using the extra arrays?ytwice.y < length, noty <= length.