Home »
VB.Net »
VB.Net Programs
VB.Net program to check the given year is leap year or not using conditional operator
By Nidhi Last Updated : October 13, 2024
Checking leap year using conditional operator
Here, we will read a year from the user and check the entered year is LEAP year or not.
VB.Net code to check the given year is leap year or not using conditional operator
The source code to check the given year is LEAP year or not using the conditional operator is given below. The given program is compiled and executed successfully.
'VB.Net program to check the given year is
'Leap year or not.
Module Module1
Sub Main()
Dim year As Integer = 0
Dim result As String
Console.Write("Enter the 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 is Leap Year",
"Entered is not Leap Year"
)
Console.WriteLine(result)
End Sub
End Module
Output:
Enter the year: 2004
Entered is Leap Year
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains the Main() method. In the Main() method we created two local variables year and result. After that, we read the value of 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 is Leap Year",
"Entered is not Leap Year"
)
In the above code, we checked the entered number is leap year or not, after that print the appropriate message on the console screen.
VB.Net Basic Programs »