Scala Program to Check a Given Number Is Exist in a Sequence or Not

Scala program to check a given number is exist in a sequence or not

// Scala program to check a given number is 
// exist in a sequence or not

import scala.collection.immutable._

object Sample {
  // Main method
  def main(args: Array[String]) {
    var nums: Seq[Int] = Seq(10, 20, 30, 45, 56, 67, 78);
    var num: Int = 0;

    printf("Enter number: ");
    num = scala.io.StdIn.readInt();

    if (nums.contains(num))
      println(num + " exists in nums sequence.");
    else
      println(num + " does not exist in nums sequence.");

  }
}

Output

Enter number: 45
45 exists in nums sequence.
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment