jeudi 25 février 2016

Doubling every letter in a statement

For my intro to java class I have an assignment that asks us to use the scanner class and a for loop and and if statement to double every letter in a statement, while tripling every exclamation point in that statement. I don't know how to do both in a for loop. This is what I have so far:

public class DoubleLetters{

    public static void main(String [] args){

        String newString = "";

        for (int j = 0; j < str.length(); j++){

            newString += str.charAt(j) + str.charAt(j);

        }
        return newString;
      }
   }
}

anyone help!

Aucun commentaire:

Enregistrer un commentaire