2022 APCS Exam Free Response Question Review

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ก.ย. 2024

ความคิดเห็น • 3

  • @maryamalali5260
    @maryamalali5260 2 ปีที่แล้ว +1

    Thank you!

  • @jaypenguin8725
    @jaypenguin8725 2 ปีที่แล้ว

    for question 1, can you just put "sum = sum * 3;" inside the if statement for bonus and then return it at the end?

    • @BytesOfPi
      @BytesOfPi  2 ปีที่แล้ว

      You sure can and the result would be the same. Looking at it from a process perspective there's one extra step doing it that way rather than returning early.
      However there is an even more elegant solution that I used that may not be evident for first time java students. If you get rid of the if statement altogether and just put:
      return isBonus() ? sum * 3 : sum;