You need to sign in to do that
Don't have an account?
Nandhuk 8
Apex basics & Database trailhead challenge i am getting an error.
public class StringArrayTest
{
public static List<String> generateStringArray(Integer n)
{
List<String> listString = new List<String>();
for(Integer i=0;i<n;i++)
{
listString.add('Test'+i);
System.debug(listString[i]);
}
return listString;
}
}
i am not getting output like test 0,test1, test 2.....
can you correct my programming whether it is correct or not
{
public static List<String> generateStringArray(Integer n)
{
List<String> listString = new List<String>();
for(Integer i=0;i<n;i++)
{
listString.add('Test'+i);
System.debug(listString[i]);
}
return listString;
}
}
i am not getting output like test 0,test1, test 2.....
can you correct my programming whether it is correct or not
Greetings to you!
Your code is correct. Please be careful with the space in 'Test '+i when you add to the List.
listString.add('Test '+i);
Use below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Try this one.
Void doesn't return type of value.So, it is getting error message.
Thankyou for the reply
I tried your method but i don't have any space between the test and +i .Still, i am getting an error.
what should to write or i recall method in the open anonymous debug mode.
Thank you for the reply
Check My Screenshot, You want output like that?
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.
My Trailhead Playground 1
Launch
Check challenge to earn 500 points
Refer to my code.
I got the output and solved it.
Thank you for the support.
Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue. *(After you choose the best answer the question is marked as “resolved”)*
Happy Learning!
Regards,
Khan Anas