Scala - Ternary Operator (Program to check whether a given number is EVEN or ODD) Code Example

The code for Ternary Operator (Program to check whether a given number is EVEN or ODD)

// Scala program to find the number is EVEN or ODD 
// using ternary operator

object Sample{  
  def main(args:Array[String]){  
    var num:Int=0
    var result:String=""
    
    print("Enter number: ")
    num = scala.io.StdIn.readInt()
    
    result = if (num%2==0) "EVEN" else "ODD"
    
    println("Number is: "+result)
  }  
}

/*
Output:
Enter number: 13
Number is: ODD
*/
Code by IncludeHelp, on August 12, 2022 23:22

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.