title: How do I use indexOf with an If Statement in Java?
body: <p>I am working on a program that when you enter an email incorrectly, it will show you an error message. If it's empty, the message will tell you it can't be blank. If there's more than 30 characters, it has to be less or equal to 30 and so on. The program I am having is that I've never used indexOf inside of an If statement. How do I code if it the input Email Address can only have one AtSign(@)? or Code that if there isn't a @ sign or there's more than 2, an error message will show up.</p>
  
  <pre><code>import javax.swing.JOptionPane;
  
  
  public class EmailandGrade {
  
  public static void main(String[] args) {
  
          // 1. Declaring Variables
  
          String strEmail;
  
  
  
          // 2. Print Prompts and User Input
          strEmail = JOptionPane.showInputDialog("Enter a user email:");
  
          // 3. If/Else Statements For Email
          if (strEmail.isEmpty())
          {
              JOptionPane.showMessageDialog(null, "Can't be blank");
          }
          else if (strEmail.length() &gt; 30)
          {
              JOptionPane.showMessageDialog(null, "Email must be less than or equal 30 characters");
          }
          else if (!strEmail.endsWith("@student.stcc.edu"))
          {
              JOptionPane.showMessageDialog(null, "Must end with in: @student.stcc.edu");
          }
          else if (strEmail.indexOf("@") )
          {
              JOptionPane.showMessageDialog(null, "Can only have one @ in it");
          }
  </code></pre>