Campbell Ritchie wrote:Please have a look at the administrative private message I sent a minute or so ago.
[Pedantic mode]There is no such thing as a 2D array in Java. You only get arrays of arrays, which are more versatile[/Pedantic mode]
You only need one array for counting frequencies, if you are using arrays. No need for two arrays. You simply need a frequency array, and you can increment the elements as you pass the letters. That bit is really easy. You probably don't need the ABCD... array either.
Campbell Ritchie wrote:I take your point. You need some way to link letters to frequencies.
Set up a class which incorporates a letter, a frequency and a replacement letter. Put those in the array from A to Z. Remember a char is not a character at all, despite what people say. It is a number. You can do arithmetic on it. Try this:So you can use each letter to access the array and call its increment() method.
Make your class implement the Comparable interface, and simply subtract the two frequencies in the compareTo() method.
Then set the replacement character after sorting, and comparison with the frequencies. According to this Oxford English Dictionary website, that is EARIOTNSLCUDPMHGBFYWKVXZJQ. But you have been given a different set of frequencies, which you had best use.
Then use that replacement in your original String.
Campbell Ritchie wrote:I tried it last night with both the frequency tables on that Oxford website, and got a decrypted output . . . and couldn't understand it
![]()
If you want to get the index of your 26-element array, try myLetters['z' - 'a'].
Create a simple method which demonstrates an array like that.
Then go through your coded String, and for each of the letters, increment the count in your array. You can even iterate through the array like thisSee if you can get that bit working. See whether that helps at all. Note you can use upper-case and lower-case versions of that for loop.
Henry Wong wrote:
When you swap the freqs, shouldn't you swap the letters too? After all, the letter and freqs should stay together right?
Henry
What do you mean, I ain't kind?
lisa broker wrote:I just wanna say one thing, programming require patient a lot, keep going
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|