samedi 14 avril 2018

How can I randomly display a single character from a given word

I'm working on a side project where the user views an image and then has to fill in the bottom half of the screen with their answer. There is also a hint feature that is implemented but currently it only gives the hint in order letter by letter.

What I am trying to do is make it so that every time the user presses the hint button a random letter of the answer appears. This is currently what I have:

public String letterHint(int counter, String answer) {
    StringBuilder string = new StringBuilder();
    Random RNG = new Random();
    char[] letters = answer.toCharArray();


    for (int i = 0; i < answer.length() ; i++) {
            if (i <= count - 1){
            if (answer.charAt(i) == ' '){

                string.append(answer.charAt(RNG.nextInt(answer.length())));
            }
        }
return string.toString();
}

I thought about using a boolean and taking each index of the answer but I'm unsure about how to do that since the answer changes based on the current "card" the user is looking at.

Any help is appreciated!




Aucun commentaire:

Enregistrer un commentaire