Scala - Ternary Operator (Check Leap Year) Code Example

The code for Ternary Operator (Check Leap Year)

// Scala program to find the given year is leap year or not 
// using ternary operator

object Sample{  
  def main(args:Array[String]){  
    var year:Int=0
    var result:String=""
    
    print("Enter year: ")
    year = scala.io.StdIn.readInt()
    
    result = if (((year % 4 == 0) && (year%100 != 0)) ||((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0))) "Entered year is LEAP YEAR" else "Entered year is not LEAP YEAR"
    
    println(result)
  }  
}
Code by IncludeHelp, on August 12, 2022 23:25

Comments and Discussions!

Load comments ↻






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