ApexSensei

Drills Apex basics

Add up the seats

A for-each loop runs once for every item in a list: for (Integer seat : seats) { }.

Your task

Use a for-each loop over seats to add every number to total.

String companyName = 'RidgePoint Capital';
List<Integer> seats = new List<Integer>{ 3, 5, 2 };
Integer total = 0;
Boolean reviewed = false;

Requirements

  1. The loop should be for (Integer seat : seats) {
  2. Each item should be added to total inside the loop
  3. total should be 0 before the loop
  4. The answer should be worked out, not typed

Sign in to open this drill