Advanced Topics MCQ

Code Tracing: Computer Science Foundations

Practice mode shows one question at a time and lets students check each answer before moving on.

All AT CS Tests

For practice use only.

Code Tracing: Computer Science Foundations

Code Tracing: Computer Science Foundations with immediate answer checks and explanations for Advanced Topics in Computer Science.

Question 1 of 25

Answered 0 of 25

Choose one answer.

Trace the helper method and loop. What is printed?

public class ScoreAudit
{
    private static int bucket(int raw, int bonus)
    {
        int adjusted = raw + bonus;
        if (adjusted > 100) adjusted = 100;
        if (adjusted < 0) adjusted = 0;
        return adjusted / 10;
    }

    public static void main(String[] args)
    {
        int[] raw = {82, 67, 91, 58, 73};
        int total = 0;
        int audit = 0;
        for (int i = 0; i < raw.length; i++)
        {
            int bonus = (i % 2 == 0) ? 3 : -2;
            int b = bucket(raw[i], bonus);
            total += b;
            if (b >= 9) audit += i + 1;
            else if (b <= 6) audit -= i;
        }
        System.out.println(total + ":" + audit);
    }
}