Help with Simple Java?

When will i map letters in a very string which i input to another string of people.

As an example if I have:
confidential static String map=”ererjkerjerjfvflerlghgd..”

Then I enter in a string.
As an example “cat” will output “eeg”

How might I produce the rule to map each letter with the input string towards the map string

Here’s how I’d personally implement it:

…..open public static emptiness main(String args)

……….String alphabet = “abcdefghijklmnopqrstuvwxyz”;
……….String map = “ererjkerjerjfvflerlghgdaerjaks”;

……….String input = “cat”;
……….String output = “”;

……….char currentChar;
……….int index = 0;

……….// picture through each one character inside the input string
……….for(int my partner and i = 0; my partner and i < source.length(); i++)

……………// seize single identity from insight moving kept to right
……………currentChar = insight.charAt(i);

……………// get the index on this character within the alphabet string
……………// beginning at 0 (ex.d = 2)
……………index = alphabet.indexOf(currentChar); // get the index

……………// develop index by above to help read this map character
……………// (ex.guide.charAt(2) = e)
……………productivity += guide.charAt(index) + “”;

……….
……….
……….Process.out.println(“Input:\t” + input);
……….Process.out.println(“Output:\t” + output);
……….
…..

The two primary HashMap’s procedures are:

* get( Thing key ) – returns the value associated with specified penetrate this hash guide, or null if you have no value due to this key
* put(K critical, V value) — associates the specified value with all the specified penetrate this map

There are numerous other handy HashMap’s procedures:

* containsKey(Object key) — (boolean) earnings true in the event that this map sports a value for the specified key
* values() — returns a group of this values confined in this map
* keySet() — returns a regular view belonging to the keys confined in this map
* remove(Object key) – removes the particular mapping regarding key from this map in the event present
* isEmpty() – (boolean) results true when this guide contains absolutely no key-value mappings

Following example opens file specified within FileReader’s merchandise constructor along with calculates number of occurrences for every latin-letter word of mouth (assuming of which words tend to be separated simply by any non-letter characters).

Leave a Reply