Q:

Write a Scala program to test if a given string contains the specified sequence of char values

0

Write a Scala program to test if a given string contains the specified sequence of char values.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_String {  
  def test(str1: String, str2: String): Boolean = {
    str1.contains(str2)   
  }
  def main(args: Array[String]): Unit = {
        var str1 = "Scala Exercises and Python Exercises";
        var str2 = "and";
        println("Original String: " + str1);
        println("Specified sequence of char values: " + str2);
        println("Test if the said string contains the specified sequence of char values!")
        println(test(str1, str2))
        str1 = "Scala Exercises and PHP Exercises";
        str2 = "Python";
        println("Original String: " + str1);
        println("Specified sequence of char values: " + str2);
        println("Test if the said string contains the specified sequence of char values!")
        println(test(str1, str2))
      }
}
Sample Output:
Original String: Scala Exercises and Python Exercises
Specified sequence of char values: and
Test if the said string contains the specified sequence of char values!
true
Original String: Scala Exercises and PHP Exercises
Specified sequence of char values: Python
Test if the said string contains the specified sequence of char values!
false

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now