Swift Programming Exercises, Practice, Solution : Array
Swift Array [38 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
1. Write a Swift program to check if 5 appears as either the first or last element in a given array of integers. The array length should be 1 or more.
Click me to see the solution
2. Write a Swift program to check whether the first element and the last element of a given array of integers are equal. The array length must be 1 or more.
Click me to see the solution
3. Write a Swift program to test if two given arrays of integers have the same first and last element. Both arrays length must be 1 or more.
Click me to see the solution
4. Write a Swift program to compute the sum of all the elements of a given array of integers and length 4.
Click me to see the solution
5. Write a Swift program to rotate the elements of an array of integers to left direction. Therefore {1, 2, 3} yields {2, 3, 1}.
Click me to see the solution
6. Write a Swift program to create a new array with the elements in reverse order of a given array of integers.
Click me to see the solution
7. Write a Swift program to find the larger value of a given array of integers and set all the other elements with that value. Return the changed array.
Click me to see the solution
8. Write a Swift program to compute the sum of the first 2 elements of a given array of integers. Return 0 if the length of the given array is 0 and return the first element value If the array length is less than 2.
Click me to see the solution
9. Write a Swift program to create a new array of length 2 containing the middle elements from two give array of integers and length 3.
Click me to see the solution
10. Write a Swift program to create a new array of length 2 containing the first and last elements from a given array of integers. The given array length must be 1 or more.
Click me to see the solution
11. Write a Swift program to test if an array of integers contains a 3 or a 5.
Click me to see the solution
12. Write a Swift program to test if an array of integers does not contain a 3 or a 5.
Click me to see the solution
13. Write a Swift program to create a new array with double the length of a given array of integers and its last element is the same as the given array. The given array will be length 1 or more. By default, a new integer array contains all 0's.
Click me to see the solution
14. Write a Swift program to check if a given array of integers contains 3 twice, or 5 twice.
Click me to see the solution
15. Write a Swift program to check if two given arrays of integers have 0 as their first element.
Click me to see the solution
16. Write a Swift program to compute the sum of the values of two given array of integers and each length 2. Find the array which has the largest sum and return the first array if the sum of two given arrays are equal.
Click me to see the solution
17. Write a Swift program to create an array of length 2 containing the middle two elements from a given array of integers and even length 2 or more.
Click me to see the solution
18. Write a Swift program to test if an array of length four containing all their elements from two given array (each length two) of integers,.
Click me to see the solution
19. Write a Swift program to swap the first and last elements of a given array of integers. Return the modified array (length will be at least 1).
Click me to see the solution
20. Write a Swift program to create a new array of length 3 containing the elements from the middle of a given array of integers and length will be at least 3.
Click me to see the solution
21. Write a Swift program to find the largest value from the first, last, and middle values in a given array of integers and length will be at least 1.
Click me to see the solution
22. Write a Swift program to create a new array, taking first two elements from a given array of integers. If the length of the given array is less than 2 use the single element of the given array.
Click me to see the solution
23. Write a Swift program to create a new array taking the first element from two given arrays of integers. If either array is length 0, ignore that array.
Click me to see the solution
24. Write a Swift program to count the number of even integers in the given array.
Click me to see the solution
25. Write a Swift program to find the difference between the largest and smallest values in a given array of integers and length 1 or more.
Click me to see the solution
26. Write a Swift program to compute the sum of the numbers of a given array of integers except the number immediately after a 11.
Click me to see the solution
27. Write a Swift program to check if a given array of integers contains a 3 next to a 3 somewhere.
Click me to see the solution
28. Write a Swift program to test if the number of 1's is greater than the number of 3's of a given array of integers.
Click me to see the solution
29. Write a Swift program to test if every element is a 2 or a 5 of a given array of integers.
Click me to see the solution
30. Write a Swift program to check if a given array of integers contains no 2's or it contains no 5's.
Click me to see the solution
31. Write a Swift program to check if a given array of integers contains a 3 next to a 3 or a 5 next to a 5, but not both.
Click me to see the solution
32. Write a Swift program to test if a given array of integers contains two 5's next to each other, or there are two 5's separated by one element.
Click me to see the solution
33. Write a Swift program to test if there is a 1 in the array with a 3 somewhere later in a given array of integers.
Click me to see the solution
34. Write a Swift program to test if a given array of integers contains either 2 even or 2 odd values all next to each other.
Click me to see the solution
35. Write a Swift program to test if the value 5 appears in a given array of integers exactly 2 times, and no 5's are next to each other.
Click me to see the solution
36. Write a Swift program to test if every 3 that appears in a given array of integers is next to another 3.
Click me to see the solution
37. Write a Swift program to test if a given array of integers contains three increasing adjacent numbers.
Click me to see the solution
38. Write a Swift program to create a new array that is left shifted from a given array of integers. So [11, 15, 13, 10, 45, 20]
Click me to see the solution
Swift Programming Code Editor:
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/swift-programming-exercises/array/index.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics