title: How to compare without getting negative value when char is a space
body: <p>Beginner here, We were assigned an assignment to find common consonants in two different strings. This code works perfectly if there is no space in the input but in this assignment we are taking inputs from our user and they are first and last names. If there is no space I get correct value of common characters but when there is a space in between first and last names it will give me an index out of bounds error because the space makes it a negative number. Any help would be nice thank you.</p>
  <pre><code>public static int commonCharacters(String string1, String string2) {
          final int alphabetLength = 26;
          int count = 0;
  
          int[] counting1 = new int[alphabetLength];
          int[] counting2 = new int[alphabetLength];
  
          Arrays.fill(counting1, 0);
          Arrays.fill(counting2, 0);
  
          for (char c : string1.toCharArray()) {
              c = Character.toLowerCase(c);
              counting1[c - 'a']++;
               }
          for (char c :  string2.toCharArray()) {
              c = Character.toLowerCase(c);
              counting2[c - 'a']++;
          }
          for(int i = 0; i &lt; alphabetLength; i++) {
                  System.out.printf(String.valueOf(counting1[i]),counting2[i]);
  
                  count += Math.min(counting1[i], counting2[i]);
  
          }
          return count == 0 ? 1 :count;
  
  
      }
  }
  </code></pre>