You need to sign in to do that
Don't have an account?
BijayS
My Apex Class looks like this :
public class StringArrayTest {
public static List<String> generateStringArray(Integer n) {
List<String> generateString = new List<String>();
for(Integer i = 0; i <= n ; i++) {
string formattedString = 'Test ' + i;
generateString.add(formattedString);
}
System.debug(LoggingLevel.INFO, 'Formatted String for Trail Head'+generateString);
return generateString;
}
}
Not Sure whats wrong here that i am getting the error.
Getting Error While taking the challenge for Getting Started with Apex
My Apex Class looks like this :
public class StringArrayTest {
public static List<String> generateStringArray(Integer n) {
List<String> generateString = new List<String>();
for(Integer i = 0; i <= n ; i++) {
string formattedString = 'Test ' + i;
generateString.add(formattedString);
}
System.debug(LoggingLevel.INFO, 'Formatted String for Trail Head'+generateString);
return generateString;
}
}
Not Sure whats wrong here that i am getting the error.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000005KAQIA2
Simply put, your array is returning 1 more record than it should be, because your loop operates over i <= num instead of just i < num.
Please mark this as resolved if your issue resolved