title: Keep getting an error when I run this code
body: <p>I am currently taking Programming 1 and learning Java. Here is my assignment...</p>
  
  <p>Ask user to enter a number and then in a loop, find any 2 numbers that they are the same and next to each other. And then display the number in the loop. For example, if user enters 133455662, the program displays 356. For simplicity, assume user never will enter all three numbers the same and next to each other</p>
  
  <p>Here is the code I've come up with, except I keep getting an error...</p>
  
  <pre><code>public static void main(String[] args){
  
      String num = "";
      String result = "";
  
      System.out.println("Enter a number");
      Scanner s = new Scanner(System.in);
      num = s.next();
      int len = num.length();
  
      for(int n = 0;n&lt;len;n++){
          char c = num.charAt(n);
          char c2 = num.charAt(n+1);
          if(c == c2){
              result = result + c;
          }
          }
      System.out.println(num);
      }
  </code></pre>
  
  <p>This is the error I get...</p>
  
  <blockquote>
    <p>run: Enter a number 001123455 Exception in thread "main"
    java.lang.StringIndexOutOfBoundsException: String index out of range:
    9     at java.lang.String.charAt(String.java:658)     at
    CS120_Labs.Homework09_C.main(Homework09_C.java:18)
    C:\Users\Fletcher\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
    Java returned: 1 BUILD FAILED (total time: 6 seconds)</p>
  </blockquote>
  
  <p>Thanks again for anyone that can help!</p>