A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Linear Search in Kotlin page! Here, you'll find the source code for this program as well as a description of how the program works.
fun main(args: Array<String>)
{
// store usage message in variable
val message = "Usage: please provide a list of integers (\"1, 4, 5, 11, 12\") and the integer to find (\"11\")"
// validate input array is correct size and does not contain empty Strings
if(args.size !=2 || args[0].isBlank() || args[1].isBlank())
{
println(message)
return
}
// convert input number String into a List of integers, invalid characters are converted to null
val intList = args[0].split(",").map { it.trim().toIntOrNull() }
// convert input key String into an int, invalid characters are converted to null
val key = args[1].toIntOrNull()
// check if the List or the key contains null (invalid) elements
if(null in intList || key == null)
{
println(message)
return
}
// check if key is in the List and print returned boolean
println(key in intList)
}
Linear Search in Kotlin was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.