Home >>VB.Net Programs >VB.Net program to check the given year is leap year or not using conditional operator
Here, we can read the user's year and check whether or not the year entered is a LEAP year.
Program :
The source code for checking the specified year is LEAP year or the conditional operator is not included below. The program given is compiled and successfully executed.
Example
Module Module1
Sub Main()
Dim year As Integer = 0
Dim result As String
Console.Write("Enter Your year : ")
year = Integer.Parse(Console.ReadLine())
result = If(((year Mod 4 = 0) AndAlso Not (year Mod 100 = 0)) OrElse
((year Mod 4 = 0) AndAlso (year Mod 100 = 0) AndAlso (year Mod 400 = 0)),
"Entered Year is Leap Year",
"Entered Year is not Leap Year"
)
Console.WriteLine(result)
End Sub
End Module
Explanation:
We created a Module1 module in the program above that contains the Main() method. Two local variables year and result were generated in the Main() method. We then read the importance of the year.
result = If(((year Mod 4 = 0) AndAlso Not (year Mod 100 = 0)) OrElse ((year Mod 4 = 0) AndAlso (year Mod 100 = 0) AndAlso (year Mod 400 = 0)), "Entered Year is Leap Year", "Entered Year is not Leap Year" )
In the above code, we checked whether or not the number entered is a leap year, after which the appropriate message is printed on the console screen.