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
Arunkumar Pandyan RamarArunkumar Pandyan Ramar 

error message : generateStringArray method failed while doing the Apex module exercise in trailhead

I am getting the following error message

Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."

My code is as shown below.

public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer n){
        List<String> str = new List<String>(n);
        for(Integer j=0;j<n ;j++){
           str.add('Test '+String.valueOf(j));
          }
        return str ;
    }
}

When I test this on the debug-->open  execute anonymous window,

with the following code, it runs successfully.

List<String> ls = StringArrayTest.generateStringArray(10);
for (Integer m=0;m<10;m++){
    System.debug(ls[m]);
}