title: Why isn't the nested loop adding value separately, instead of adding all together?
body: <blockquote>
    <p>Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. 
    What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each 
    letter divides the plane into regions. For example letters "A", "D", "O", "P", "R" divide the plane
    into two regions so we say these letters each have one hole. Similarly, letter "B" has two holes 
    and letters such as "C", "E", "F", "K" have no holes. We say that the number of holes in the text 
    is equal to the total number of holes in the letters of the text. Help Chef to determine how many 
    holes are in the text.</p>
  </blockquote>
  
  <p>Why isn't the nested loop adding value separately, instead of adding all together?</p>
  
  <pre><code>public class Practice{
      public static void main(String[] args){
          Scanner sc = new Scanner(System.in);
          int totalnumber = sc.nextInt();
          String[] noString = new String[totalnumber];
  
          for(int i = 0; i &lt; totalnumber; i++){
              //System.out.println("Enter the word for " + i);
              noString[i] = sc.next();
          }
  
          int totalHole = 0;
          int[] total = new int[totalnumber];
  
          char[] singleHole = {'A','Q','R','O','P','D'};
          char B = 'B';
          int counter = 0;
  
          for(int a = 0; a &lt; totalnumber; a++){
              for(int i = 0; i &lt; noString[counter].length();i++){
                  for(int j = 0; j &lt; singleHole.length; j++){
                      if(noString[a].charAt(i) == singleHole[j]){
                          totalHole = totalHole + 1;
                      }
                  }
                  if(noString[a].charAt(i) == B){
                      totalHole = totalHole + 2;
                  }
              }
              counter = counter + 1;
              total[a] = totalHole;
              System.out.println(total[a]);
          }
      }   
  }
  </code></pre>