Prev Next

Scala / Scala programs

1. Implement Selection sort program using Scala.

object SelectionSort { def main (args: Array[String]) { val myArray = Array( 14 , 2 , 5 , 1 , 2 , 6 ) for ( i <- 0 to myArray . length - 2 ) { var min = myArray(i) var pos = i for ( j <- i to myArray . length - 1 ) if (min > myArray(j)) { min = myArray(j) pos = j } if (myArray(i) != min) { val te...

Read full answer

2. Implement bubble sort using Scala.

object BubbleSort { def main (args: Array[String]) { val myArray = Array( 18 , 2 , 5 , 1 , 63 , 17 ) var unsorted_last_index = myArray . length - 2 ; while (unsorted_last_index > 0 ) { for (j <- 0 to unsorted_last_index) if (myArray(j) > myArray(j + 1 )) { val temp = myArray(j) myArray(j) = myArr...

Read full answer

3. I have a string(avbfjsjebfswncnsjfsfna) and I don't want repeated alphabets by using pure Scala programming.

The Scala program follows. Kindly share your comment/suggestion for improvement and feedback. Thanks. import scala.collection.mutable.HashSet object StringUtil { /* * The below program creates a new string object without duplicates from the original string . * please note that this programs consi...

Read full answer

«
»

Comments & Discussions