Using swift 4.0, Write a function (not method) named findName which returns a given name (passed as a parameter) |
if it is in the string array passed as a parameter, otherwise return nil |
Demonstrate calling the function findName. Using swift 4.0
func findName(array: [String],name: String) -> String {
if array.contains(name) {
return name;
}else {
return "null";
}
}
let z=findName(array: ["swarup", "alisa",
"peter"],name:"swarup")
print(z)
output:
when string in array:
output when string not in array:
the above code is executable one with screenshot.worked in online ide.searches for a string in array returns name of string if found else returns null
Using swift 4.0, Write a function (not method) named findName which returns a given name (passed...
Using Swift, Write a program that reads in a string and passes to a function named parse(digit:) that takes a string with one character as parameter. The function should return -1 if the input is not a digit character and the digit otherwise. You must use a switch statement parse(digit: "1") // 1 parse(digit: "3") // 3 parse(digit: "a") // -1
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...
Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...
use swift language Write a function that will accept an array of Emoji symbols of size N and randomly returns a sumbol from the array. This function will have one parameter, the Array of Emoji Symbols and will return One emoji symbol as a String.
1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
Write a C function named isSymmetric, the prototype of which is given below, that returns 1 if the elements of an array of integers named myArray of size n are symmetric around the middle. If the array elements are not symmetric, the function should return 0. Both the array and its size are specified as parameters.
write in java 1. Assume the availability of a method named makeLine that can be passed a non-negative integer n and a character c and return a String consisting of n identical characters that are all equal to c. Write a method named printTriangle that receives two integer parameters n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...
(c programming): write a program that contains a function named getName, that does not get any parameter and returns a character array of a random name from a constant list of 30 names, in a global array. the function returns that random name. each name in the list is a character string that consists of not more than 20 characters(not including finishing 0). the name consists of only characters from the american alphabet (a-zA-Z) and does not contain any "white"...
4. Write a static method named ConcatStrings that is passed any number of parameters of type String, and returns a single string that is the concatenation of the strings passed. (4 pts.) 5. Write a static method named ConcatObjects that is passed any number of parameters of type Object, and returns a single string that is the concatenation of the result of the call to toString() for each of the objects. (4 pts.) 6. Write a class named Triplet that...