Given a year, we have to check whether it is a Leap year or not using Ruby program.
Methods used:
- gets(): This method is a public instance method of String class which is used to take input from the console.
- puts(): This method is a public instance method of String class which is used to print Strings on the console.
Program 1:
Output
Explanation:
In the above code, you can observe that first, we have checked whether the year is divisible by 4 or not, if it is divisible by 4 then the year is simply a leap year. Otherwise, to be a leap year, it should satisfy both the conditions which are there in elsif then only it will be considered as a leap year otherwise not.
Program 2:
Output
Explanation:
In the above code, you can observe that our program is asking for a range under which we want to find the leap year. You can see that we are getting all the leap years which lie between the range.
need an explanation for this answer? contact us directly to get an explanation for this answer