You need to sign in to do that
Don't have an account?
Ram Shiva Kumar
Trail Head Scenario
hi , From trail head scenario is like this,
Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.
The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
and my code is,
Public Class StringArrayTest
{
public static List<String> generateStringArray(integer n){
List<string> srtList = new List<string>();
for(integer i=0;i<n;i++){
string s = string.valueOf(i);
srtList.add('\'Test '+i+'\'');
}
system.debug('hhh'+srtList);
return srtList;
}
}
i have run the code every this coming exactly but when i check the chalange in trail head iam getting the error ,error is asfollows,
"
Challenge Not yet complete... here's what's wrong:
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."
Plesae any one tell me the suggestion.
Regards,
Siva
Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.
The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
and my code is,
Public Class StringArrayTest
{
public static List<String> generateStringArray(integer n){
List<string> srtList = new List<string>();
for(integer i=0;i<n;i++){
string s = string.valueOf(i);
srtList.add('\'Test '+i+'\'');
}
system.debug('hhh'+srtList);
return srtList;
}
}
i have run the code every this coming exactly but when i check the chalange in trail head iam getting the error ,error is asfollows,
"
Challenge Not yet complete... here's what's wrong:
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings."
Plesae any one tell me the suggestion.
Regards,
Siva
Please check this code:
Thanks,
Dhanya
All Answers
Please check this code:
Thanks,
Dhanya
Challenge is need to get the list of string in the format of "Test n". where as you are returning the string in the format of " 'Test n' ". so delete the extra codes you are adding before and after the test n.
let me know if you face any issues. Also mark this answer as best answer if this answers you .
Thanks and Regards,
Sai Krishna Tavva.
And Thanks to sai Krishna ,For the idea which is exactly true.