Write a Scala program to check whether a given string ends with the contents of another string

  • برمجة سكالا

Write a Scala program to check whether a given string ends with the contents of another string.

الأجوبة

object Scala_String {  
  def test(str1: String, end_str: String): Boolean = {
    str1.endsWith(end_str)   
  }
  def main(args: Array[String]): Unit = {
        val str1 = "Python Exercises";
        val str2 = "Python Exercise";

        // The String to check the above two Strings to see
        // if they end with this value (se).
        val end_str = "se";

        // Check first two Strings end with end_str
        val ends1 = test(str1, end_str)
        val ends2 = test(str2, end_str)
        // Display the results of the endsWith calls.
        println(""" + str1 + "" ends with " +
            """ + end_str + ""? " + ends1);
        println(""" + str2 + "" ends with " +
            """ + end_str + ""? " + ends2);
      }
}

Sample Output:
"Python Exercises" ends with "se"? false
"Python Exercise" ends with "se"? true
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...