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
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer