public class OddNumberSum { public static void calculateSum() { List oddNumbers = new List(); // List to store odd numbers Integer num = 1; // Start from 1 Integer sum = 0; // Variable to store the sum Integer position = 0; // Position index for the list // Use a while loop to add odd numbers to the list while (num <= 20) { if (num % 2 != 0) { // Check if the number is odd oddNumbers.add(num); } num++; // Increment number } // Debug log to print the list of odd numbers System.debug('Odd Numbers List: ' + oddNumbers); // Loop through the list and sum only numbers at even positions for (Integer i = 0; i < oddNumbers.size(); i++) { if (i % 2 != 0) { // Check if index is even-positioned (1-based) sum += oddNumbers[i]; } } // Print the final sum in the debug log System.debug('Sum of numbers at even positions: ' + sum); } }