Write a Scala program to check whether the first two characters present at the end of a given string
- برمجة سكالا
- 2021-09-24
- mhanasmh00489829403
الأجوبة
object Scala_String {
def test(str1: String): Boolean = {
if (str1.length < 2)
return false;
else if (str1.substring(0,2).equals(str1.substring(str1.length-2, str1.length)))
return true;
else
return false;
}
def main(args: Array[String]): Unit = {
var str1 = "educated";
println("The given strings is: "+str1);
println("If first two characters appear in the last! "+test(str1));
str1 = "ABCDEFBA";
println("The given strings is: "+str1);
println("If first two characters appear in the last! "+test(str1));
}
}
Sample Output:
The given strings is: educated If first two characters appear in the last! true The given strings is: ABCDEFBA If first two characters appear in the last! false
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال
معلومات ذات صلة