title: How to check game win and display win message Java
body: <p>I have created a program where you need to decode the word &quot;program&quot; however I am trying to detect when the user wins and matches all the letters, I am trying to display this but I am facing an issue where, even when all the letters in the word match a winning message is not displayed</p>
  <p>my code</p>
  <p>'''</p>
  <pre><code>public static void main( String[] args ) 
  {
  
  
      String szDecryptedWord = &quot;Encryptedword&quot;;
      String szEncryptedWord = &quot;1223567891234&quot;;
      
      //creates char array for &quot;$2%824*&quot;
      char [] charArr = szEncryptedWord.toCharArray();
  
      
      for(int i2 = 0; i2 &lt; 10; i2++) 
      {
          Scanner sc = new Scanner (System.in);
  
          System.out.println(&quot;Crack the enigma code (guess a letter) &quot;+ szEncryptedWord + &quot; :&quot;);
          char someChar = sc.next().charAt(0);
          
          for(int i = 0; i &lt; szDecryptedWord.length(); i++) 
          {
              char DecryptedCharacter = szDecryptedWord.charAt(i); 
              char encryptedCharacter = szEncryptedWord.charAt(i); 
          
  
              if(someChar == DecryptedCharacter) 
              {
                  System.out.println(&quot;You have decoded the Character &quot; + someChar + &quot; Which was &quot; + encryptedCharacter);
                  
              }
          }
  
          //replace letter with encrypted word String szEncryptedWord = &quot;$2%824*&quot;;
          
          int indexOfLetter = szDecryptedWord.indexOf(someChar);
          
          //loop if index is positive or 0
          while(indexOfLetter &gt;= 0 ) 
          {
              charArr[indexOfLetter] = szDecryptedWord.charAt(indexOfLetter);
              indexOfLetter = szDecryptedWord.indexOf(someChar, indexOfLetter +1);
          }
  
          szEncryptedWord = String.valueOf(charArr);
          System.out.println(szEncryptedWord);
          
          if(szEncryptedWord == &quot;encryptedword&quot;) 
          {
          System.out.println(&quot;you win!&quot;)
           }
  
  }
  </code></pre>
  <p>'''</p>