A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
 
  
  Welcome to the Linear Search in Scala page! Here, you'll find the source code for this program as well as a description of how the program works.
object LinearSearch {
    def main(args: Array[String]): Unit = {
        if (args.length != 2) {
            println("Usage: please provide a list of integers (\"1, 4, 5, 11, 12\") and the integer to find (\"11\")")
            return
        }
        
        val list = args(0);
        val key = args(1);
        try {
            val arr = list.split(",").map(_.trim.toInt)
            val target = key.trim.toInt
           
            var flag = 0
            var pos = -1
            for (i <- arr.indices) {
                if (arr(i) == target) {
                    flag = 1
                    pos = i
                    println("true")
                    return
                }
            }
            if (flag == 0) {
                println("false")
            }
        } catch {
            case _: NumberFormatException =>
            println("Usage: please provide a list of integers (\"1, 4, 5, 11, 12\") and the integer to find (\"11\")")
        }
    }
}
Linear Search in Scala 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.