Code Snippet Not working as expected

  if(digitalRead(4) == HIGH){
   a = 1;
  }else if(digitalRead(7) == HIGH){
    b = 1;
  }
  if(digitalRead(4) == LOW && a == 1){
    num = num + 1;
    ins[num] = 2;
    Serial.print(num);
    a = 0;
    Serial.print(num);
  }
   if(digitalRead(7) == LOW &&  b == 1){
    num = num + 1;
    ins[num] = 1;
    Serial.print(ins[num]);
    b = 0;
  }
  if(num == 5){
    Serial.println("5le");
    s = true;
    for(int i = 0; i < 5; i++){
      Serial.println(ins[i]);
      if(pass[i] == ins[i]){
        
        
        
      }else{
        s = false;
      }
    }
    
    num = 0;
  }

My system for how to check when a button is pressed is when the pin the button is connected goes HIGH then a is set at 1. then it detects at any time if the button is LOW and a == 1.
but the weird thing is when i press the button 5 times you would expect the Output on the Serial Screen to be "11223344555le" Correct? but Seem to be getting "1122334452" and the procedure on the is that i press the button connected to pin4 5 times.
can someone please tell me what im doing wrong?
My code is written in JAVA format so im not sure if theres something different about the 2 languages that im missing.

Had a look through your code and I cant see anything wrong with it.

However, as you haven't included your variable declarations this could be the problem. My best guess is that you are overwriting the end of the ins array. Unlike java overwriting the end of an array doesn't raise an exception directly.

How big is the ins array?

My system for how to check when a button is pressed is when the pin the button is connected goes HIGH then a is set at 1. then it detects at any time if the button is LOW and a == 1.

That's a pretty lousy way to do it.

int prevState4 = LOW;
int currState4;

void loop()
{
   currState4 = digitalRead(4);
   if(currState4 != prevState4)
   {
      // A transition occurred, from released to pressed or from pressed to released
      if(currState4 == HIGH) // Assuming HIGH means pressed
      {
         num++;
         ins[num] = 2;
      }
   }
   prevState4 = currState4;
}

Dealing with pin 7 is left as an exercise for the user. Changing the code to detect a release, instead, is also left as an exercise (trivial).

Notice that the two blocks of code that deal with the switches supposedly being released are NOT the same, with the exception of the stored values. Different things are being printed in the two blocks.