You need to sign in to do that
Don't have an account?
Fayazuddin Mohammed
StringArrayTest
Hello, Can anyone please tell me what's wrong with my code. When I run it executes fine and o/p also seems to be correct. Howeve the trailhead challenge shows error "Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."
public class StringArrayTest {
public static List <String> generateStringArray(Integer n) {
List<String> numbers = new List<String>();
for (integer i=0;i<=n; i++){
numbers.add('Test '+String.valueOf(i));
System.debug(numbers[i]);
}
return numbers;
}
}
public class StringArrayTest {
public static List <String> generateStringArray(Integer n) {
List<String> numbers = new List<String>();
for (integer i=0;i<=n; i++){
numbers.add('Test '+String.valueOf(i));
System.debug(numbers[i]);
}
return numbers;
}
}
for(Integer i=0;i<n;i++)
NOTE :- It shoud be < n not <=n
PLease check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000BWSOIA4
2) https://developer.salesforce.com/forums/?id=906F0000000BTQ9IAO
Let us know if this will help you
I was using only this line StringArrayTest.generateStringArray(5); in my
Execute anonymous window. I used below 2 lines after checking the links you have posted. It works fine.
list<string> myArray = StringArrayTest.generateStringArray(5);
system.debug(+myArray); // This line is important I think as it gives the output in our desired format.