title: Print index position of letter from sentence using JOptionPane
body: <p>I need to ask the user to input a sentence and then a letter.
  The program should then print out how many letters the sentence contains. Also the index position of
  the specified character that the user inputted.
  My problem is that I don't know how to find the position of that character.</p>
  <p>NOTE: I have searched the web for answer.</p>
  <pre><code>import javax.swing.*;
  
  public class Main {
      public static void main(String[] args) {
  
          String sentence;                //Store the users senctence
          String sentence2;               //Stores the letter that the user wants to count.
          int index;
          sentence = JOptionPane.showInputDialog(&quot;Write a sentence&quot;);
          sentence2 = JOptionPane.showInputDialog(&quot;Write a letter&quot;);
  
          int sLenght = 0;
          int countCha = sentence2.indexOf(sentence2);
  
          if (sentence == null || sentence.equals(&quot;&quot;))
              JOptionPane.showMessageDialog(null, &quot;You need to input a sentence to continue&quot;);
          else {
  
              for (int i = 0; i &lt; sentence.length(); i++) {
                  if (sentence.charAt(i) != 1)
                      sLenght++;
              }
  
              JOptionPane.showMessageDialog(null, &quot;The sentence contains&quot; + &quot; &quot; + sLenght +
                      &quot; &quot; + &quot;characters&quot; + &quot;\n&quot; + &quot;Tecknet&quot; + &quot; &quot; + sentence2 + &quot; &quot; + &quot;occurs&quot; + sentence.indexOf(sentence2) + &quot; &quot; + &quot;times&quot;);
          }
      }
  }
  </code></pre>