function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Heiner GoehlmannHeiner Goehlmann 

Executing the 'generateStringArray' method failed

Hi Dev Community,

I am running crazy: since yesterday I have tried for hours and hours to pass the check, read plenty of threads in this forum, but have not yet passed the check.

This is my actual status:
public class StringArrayTest 
{
    // public static method generateStringArray
    public static List<String> generateStringArray( Integer n ) 
    {
        // Make i known
        Integer i;
        // Initialize table of strings
        List<String> table = new List<String>();
        // Add elements to the list
        for (i=0; i<n; i++);
        {
            table.add('Test ' + i);
        }
        return table;
    }
}
What the hell is wrong? There must be something I do not see, but what is it?
May I ask for your help, please?

BTW: where may I find instructions on how to add apex code into posts?

 
Best Answer chosen by Heiner Goehlmann
ManojjenaManojjena
Hi Heiner Goehlmann,
Try with below code it will work .Only probelm is that you have added semicolon after for loop .
 
public class StringArrayTest 
{
    // public static method generateStringArray
    public static List<String> generateStringArray( Integer n ) 
    {
        // Make i known
        Integer i;
        // Initialize table of strings
        List<String> table = new List<String>();
        // Add elements to the list
        for (i=0; i<n; i++){
            table.add('Test ' + i);
        }
        return table;
    }
}
Let me know if it helps !!
Thanks
Manoj

All Answers

ManojjenaManojjena
Hi Heiner Goehlmann,
Try with below code it will work .Only probelm is that you have added semicolon after for loop .
 
public class StringArrayTest 
{
    // public static method generateStringArray
    public static List<String> generateStringArray( Integer n ) 
    {
        // Make i known
        Integer i;
        // Initialize table of strings
        List<String> table = new List<String>();
        // Add elements to the list
        for (i=0; i<n; i++){
            table.add('Test ' + i);
        }
        return table;
    }
}
Let me know if it helps !!
Thanks
Manoj
This was selected as the best answer
Heiner GoehlmannHeiner Goehlmann
Hi Manoj

you just made my (sun)day. Thanks a lot - that change made the method work.

Regards, Heiner