Write a Scala program to check a given list is a palindrome or not.
object Scala_List { def is_Palindrome[A](list_nums: List[A]):Boolean = { list_nums == list_nums.reverse } def main(args: Array[String]): Unit = { println("Result: " + is_Palindrome(List(1,2,3,4,3,2,1))); println("Result: " + is_Palindrome(List(1,2,3))); } }
Sample Output:
Result: true Result: false
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer