Your question is Explaining Code Execution. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
You're a backend engineer at Interactive Process Technology, working on a batch job that applies discounts to a set of pending orders and prints a run summary to the deploy log. Here is the method your interviewer hands you.
public class DiscountCalculator {
static int callCount = 0;
static int applyDiscount(int price) {
callCount++;
return price - (price / 10);
}
public static void main(String[] args) {
int[] prices = {50, 99, 100, 250};
int total = 0;
int i = 0;
while (i < prices.length) {
int discounted = applyDiscount(prices[i]);
total += discounted;
i++;
}
System.out.println("Processed: " + callCount + " orders");
System.out.println("Total after discount: $" + total);
System.out.println("Average order: $" + total / prices.length);
System.out.println("Message: " + 1 + 2 + " items, " + (1 + 2) + " unique SKUs");
}
}
Explain exactly what gets printed to the console when this runs, line by line, and explain your reasoning for each line rather than just stating the final numbers.