I am making a "Code Decoder" - So there are 3 lines, the first is the reference string, the second is jumbled, and then the third is calculated based on matching the first and second strings. Example:
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
UIFARVJDLACSPXOAGPYAKVNQTAPWFSAUIFAMB ZAEPH
XFABSFAWFSZACBEAQFPQMFAEPJOHAWFSZACBEAUIJOHTAIBAIB
What I'm doing is getting the 3 strings, converting them to char arrays, then looking through the first string, finding where it is in the array of the alphabet, then at that position I enter the letter from the second string on another array at the same place. Therefore, later, I can find a letter in the alphabet and get its corresponding letter in the second array.
Problem - nothing is inputting into the second array... It comes up empty.
Let me know if any clarification is needed.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter First String:"); // First String
String first_string = br.readLine();
System.out.print("Enter Second String:"); // Second String
String second_string = br.readLine();
System.out.print("Enter Third String:"); // Third String
String third_string = br.readLine();
char[] first = first_string.toCharArray();
char[] second = second_string.toCharArray();
char[] third = third_string.toCharArray();
char[] compare_a = {'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'}; //length = 26
char[] compare_b = new char[26]; //length = 26
for(int x =0; x < first.length ; x++){// going through first array
char first_letter = first[x]; // gets letter from first string
for(int z = 0; z < 26; z++){ // looks through alphabet for the position of the letter
if(first_letter == compare_a[z]){ // if the letter is found at a certain position
// System.out.println(first_letter + " = " + compare_a[z] + " " + compare_b[z] + " " + second[x]);
compare_b[z] = second[x]; // insert into the same position on the second array
}
}
}
for(int t =0; t<26; t++){
char m = compare_b[t];
System.out.print(m); //Printing out array of new letters
}
}
Note:
When I tried outputting the results to a string, it comes out correctly ---
letters = letters + second[x];
It just doesn't go into the array...
printlnstatements to make sure your strings contain what you expect.