title: String index out of range: 1 JAVA
body: <p>I am testing to see if the string the user entered in is a valid phone number but get </p>
  
  <blockquote>
    <p>"String index out of range: 1"</p>
  </blockquote>
  
  <p>whenever I try to run the program.</p>
  
  <pre><code>public static void main(String[] args) {
  
      Scanner sc = new Scanner(System.in);
  
      String number = "";
      boolean d1 = Character.isDigit(number.charAt(1));
      boolean d2 = Character.isDigit(number.charAt(2));
      boolean d3 = Character.isDigit(number.charAt(3));
  
      boolean d5 = Character.isDigit(number.charAt(5));
      boolean d6 = Character.isDigit(number.charAt(6));
      boolean d7 = Character.isDigit(number.charAt(7));
  
      boolean d9 = Character.isDigit(number.charAt(9));
      boolean d10 = Character.isDigit(number.charAt(10));
      boolean d11 = Character.isDigit(number.charAt(11));
      boolean d12 = Character.isDigit(number.charAt(12));
  
      System.out.println("Please enter a phone number (ddd)ddd-dddd :");
      number = sc.nextLine();
  
      if ((number.length() == 13) &amp;&amp; (number.charAt(0)=='(') &amp;&amp; (number.charAt(4)==')') &amp;&amp; (number.charAt(8)=='-') &amp;&amp; (d1==true) &amp;&amp; (d2==true) &amp;&amp; (d3==true) &amp;&amp; (d5==true) &amp;&amp; (d6==true) &amp;&amp; (d7==true) &amp;&amp; (d9==true) &amp;&amp; (d10==true) &amp;&amp; (d11==true) &amp;&amp; (d12==true)){
          System.out.println(number + " Is a valid phone number!");
      }
      else {
          System.out.println(number + " Is not a valid phone number!");
      }
      sc.close();
   } 
  }
  </code></pre>
  
  <p>This is also my first post so sorry if it is messy.</p>