ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to check the given year is leap year or not using conditional operator

Here, we are going to learn how to check the given year is leap year or not using conditional operator in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here, we will read a year from the user and check the entered year is LEAP year or not.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.