Scala - Find given year is a leap year or not using nested if Code Example

The code for Find given year is a leap year or not using nested if

// Scala program to find given year is leap year or not 
// using nested "IF"

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


/*
Output:
Enter year:2021
Given YEAR is not leap year
*/
Code by IncludeHelp, on August 12, 2022 23:19

Comments and Discussions!

Load comments ↻






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