Learn Arrays and For Loops in Java and Improve your Self-Checkout Code

Поділитися
Вставка
  • Опубліковано 23 лис 2024

КОМЕНТАРІ • 2

  • @Afarine
    @Afarine 2 роки тому

    At 34:43 Why do you make a sumOfAllItems=0, then go on to do the loop for the sumOfAllItems?

    • @SipAndCode7
      @SipAndCode7  2 роки тому

      Over there we want to calculate the sum of all the items we have in the array. In order to do so we need to go through every element and add it together. Just like when you go to any self checkout when you scan each one of your items, on the screen you see the sum up to that point. That is what that variable is doing. Let me know if that doesn't make sense. If we don't create that variable we have no way of keeping track of the sum.