Scala - Find the given year is a leap year or not Code Example

The code for Find the given year is a leap year or not

// Scala program to find given year is leap year or not

object Sample{  
  def main(args:Array[String]){  
    var year:Int = 0;
    
    print("Enter number:")
    year=scala.io.StdIn.readInt()
    
    if( (year%4==0 && year%100!=0) || (year%4==0 && year%100==0 && year%400==0) )
      println("Given YEAR is leap year")
    else
      println("Given YEAR is not leap year")
  }
}


/*
Output:
Enter number:2020
Given YEAR is leap year
*/
Code by IncludeHelp, on August 12, 2022 23:12

Comments and Discussions!

Load comments ↻






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