在vb.net中,如何计算出2000-2100年之间的闰年?输出到文本框,并统计输出闰年的个数?主要是统计个数
答案:1 悬赏:70 手机版
解决时间 2021-04-01 05:19
- 提问者网友:战皆罪
- 2021-03-31 23:26
在vb.net中,如何计算出2000-2100年之间的闰年?输出到文本框,并统计输出闰年的个数?主要是统计个数
最佳答案
- 五星知识达人网友:天凉才是好个秋
- 2021-03-31 23:43
根据闰年的定义 当年份能被400整除 或者能被4整除且不能被100整除时 此年份为闰年
所以 程序如下
新建一个Button,名称为Button1,新建一个TextBox,名称为TextBox1.当按下Button1的时候 textbox1中显示闰年年份结果
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim leapyears() As Integer = GetLeapYears(2000, 2100)
Dim str As String
Try
Dim count As Integer = UBound(leapyears) + 1
str = "闰年个数:" + count.ToString
For i = 0 To UBound(leapyears)
str += " " + leapyears(i).ToString
Next
TextBox1.Text = str
Catch ex As Exception
End Try
End Sub
'''
''' 获取指定年份区间中所有闰年组成的数组
'''
''' 起始年份
''' 结束年份
'''
'''
Private Function GetLeapYears(StartYear As Integer, EndYear As Integer) As Integer()
Dim leapyears() As Integer = Nothing
Dim index As Integer = 0
For i = StartYear To EndYear
If (i Mod 400 = 0) Or (i Mod 4 = 0 And i Mod 100 <> 0) Then
ReDim Preserve leapyears(index)
leapyears(index) = i
index += 1
End If
Next
Return leapyears
End Function
所以 程序如下
新建一个Button,名称为Button1,新建一个TextBox,名称为TextBox1.当按下Button1的时候 textbox1中显示闰年年份结果
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim leapyears() As Integer = GetLeapYears(2000, 2100)
Dim str As String
Try
Dim count As Integer = UBound(leapyears) + 1
str = "闰年个数:" + count.ToString
For i = 0 To UBound(leapyears)
str += " " + leapyears(i).ToString
Next
TextBox1.Text = str
Catch ex As Exception
End Try
End Sub
'''
''' 获取指定年份区间中所有闰年组成的数组
'''
''' 起始年份
''' 结束年份
'''
'''
Private Function GetLeapYears(StartYear As Integer, EndYear As Integer) As Integer()
Dim leapyears() As Integer = Nothing
Dim index As Integer = 0
For i = StartYear To EndYear
If (i Mod 400 = 0) Or (i Mod 4 = 0 And i Mod 100 <> 0) Then
ReDim Preserve leapyears(index)
leapyears(index) = i
index += 1
End If
Next
Return leapyears
End Function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯