Skip to content
Advertisement

how to replace the vowels from a String with other vowels for encryption?

I’m doing an encryption app with 4 different methods of encryption, one of them is a vowel replace, the problem is that is not working and I’m not sure why,

this is the vowelReplace class:

JavaScript

}

this is my interface:

public interface StringEncrypter {

JavaScript

}

and the controller where I handle the input and selection of the encrypters:

public class EncrypterController {

JavaScript

}

Advertisement

Answer

As mentioned in the comments above, String.replace() returns a new string. You can just assign the output to the same variable below.

JavaScript

Also mentioned was the fact that if you replace all the ‘a’ with ‘e’ and then replace all the ‘e’ with ‘i’, all of the chars that were originally ‘a’ will wind up as ‘i’ instead of ‘e’. You could solve that as follows.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement