fork download
  1. public class NumberList {
  2.  
  3. public static void main(String[] args) {
  4. // 1. List Declaration (List of Integers)
  5. List<Integer> numbers = new List<Integer>();
  6.  
  7. // 2. Adding elements (Numbers) to the list
  8. numbers.add(3);
  9. numbers.add(7);
  10. numbers.add(12);
  11.  
  12. // 3. Working with Strings: Create a message string
  13. String message = 'The list contains these numbers: ';
  14.  
  15. // 4. Looping through the list and adding numbers to the string
  16. for (Integer num : numbers) {
  17. message += num + ', '; // Concatenating number with comma and space
  18. }
  19.  
  20. // 5. Removing the last comma and space (optional)
  21. message = message.substring(0, message.length() - 2); // Removing the last characters
  22.  
  23. // 6. Printing the final message with list elements
  24. System.debug(message);
  25. }
  26. }
Success #stdin #stdout #stderr 0.01s 8972KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #NumberList
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #NumberList (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:3: parse error, expected '}'