Goran Shakeit Goran Shakeit - 1 year ago 56
Java Question

How to create a loop for "rövarspråket", more info about "rövarspråket" below

I need to create a loop called "rövarspråket":

But the problem is that it doesn't translate correctly and specially when I translate a name the output is just 3 letters.

To check if the translation is correct I use:

consonantsx = "bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVwWxXzZ"; //Saves all consonants to string
char consonants[] = consonantsx.toCharArray(); //String to charr

System.out.println("Mata in en mening"); //Input of what you want to translate
skriv = new Scanner(System.in);
input = skriv.nextLine(); //Saves the input
length = input.length(); //Length inc. space
char array[] = input.toCharArray(); // Input to a char array

slang = "";
System.out.println("På rövarspråk:");
for(int i = 0; i<length; i++) {
for(int x = 0; x<20; x++){
if(array[i] == consonants[x])
add = array[i]+"o"+array[i];
slang = slang + add;

Answer Source

so the idea is to dublicate consonants and put "o" between them, like t becomes tot, s becomes sos. Vocals are just copied. So you need a method that tells you if a given character is a vocal or consonant to base your decision on that.

public static boolean isConsonant(char inputChar){

    final String consonantsx = "bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVwWxXzZ"; 
    char consonants[] = consonantsx.toCharArray(); // String to charr

    for(int i=0; i < consonants.length;i++){
        if(inputChar == consonants[i]){ //note that in Strings u use the equals method instead of "=="
            return true;

    return false;

Given this method you can use it in the "translator method".

    public String rovarSpraket(String normalString) {

    char[] array = normalString.toCharArray(); // Input to a char array

    System.out.println("På rövarspråk:");

    String slang = "";

    for (int i = 0; i < normalString.length(); i++) {

        String add = "" + array[i];


            add += "o" + array[i];


        slang += add;


    return slang;

This translates stubborn to sostotubobboborornon like in the wikipedia article https://en.wikipedia.org/wiki/R%C3%B6varspr%C3%A5ket.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download