-
Notifications
You must be signed in to change notification settings - Fork 11
/
Get Started with Apex
41 lines (33 loc) · 1.42 KB
/
Get Started with Apex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Challege 3:
Create an Apex class with a method that returns an array (or list) of strings.
Create an Apex class with a method 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
The method must accept an incoming Integer as a parameter, which will be used to determine the number of returned strings
The method must return a string value in the format Test n where n is the index of the current string in the array.
Solution:
public class StringArrayTest{
/*
public static List<String> generateStringArray(Integer n)
{
System.debug(n);
List<String> myArray = new List<String>();
for(Integer i=0;i<n;i++)
{
myArray.add(' Check '+i);
}
System.debug(myArray);
return myArray;
}*/
public static List<String> generateStringArray(Integer n){
System.debug(n);
List<String> str = new List<String>();
for(Integer i=0;i<n;i++)
{
str.add('Test '+i);
}
System.debug(str);
return str;
}
}