jeudi 16 avril 2020

hel >>RANDOM letters INPUT A WORD WITH THOSE LETTERS CHECK IF THE WORD IS USING THOSE RAN LETTERS. NO USING LOOP

I have generated the Random word of 7 letters. My issue is that I am not able to check if the word introduced by input is using the random letters or not. I have tried indexOf and contains and none of those are working. The closest that I got was with a for loop but it was giving me true of false for each character so JOpane was unnecessary repeating itself. If the length of the word was 4 I got 4 times same message. Could I do the same with no "for(loop)"?

not working:

for(int i=0;i<word1.length();i++){if(randomString.indexOf(word1.charAt(i) == -1)){
 JOptionPane.showMessageDialog(null, "False");}else {
 JOptionPane.showMessageDialog(null, "True");}}

//Its showing true or false as many letter as the word has because the loop. The following No working either:

if (totalRanLetters.indexOf(word1) == word1.length()) {

                JOptionPane.showMessageDialog(null, "Its true");

            }else {
                JOptionPane.showMessageDialog(null, "False");
            }



Aucun commentaire:

Enregistrer un commentaire