这个同时判定可以采用多线程做。但是一般都是使用数组循环来统计。
创新互联专注于企业成都营销网站建设、网站重做改版、镇康网站定制设计、自适应品牌网站建设、H5技术、商城网站建设、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为镇康等各大城市提供网站开发制作服务。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim A(100) As Integer
Dim n1 As Integer = 0
Dim n2 As Integer = 0
For i = 1 To 100
Randomize()
A(i) = Int(Rnd() * 1000 + 1)
If A(i) Mod 2 = 0 Then
n1 += 1
Else
n2 += 1
End If
Next
MsgBox("所产生的100个数字中偶数有" n1 "个,奇数有" n2 "个")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer = Int(Rnd() * 100)
If a Mod 2 = 0 Then
MsgBox(a "是偶数")
Else
MsgBox(a "是奇数")
End If
End Sub
通过Abs()函数对整数取绝对值,然后通过Mod 2取余计算判断,即除以2,余数是1,那么就是奇数,余数是0就是偶数。如下:
If Abs(m) Mod 2 = 1 Then
Print m "是奇数"
Else
Print m "是偶数"
End If
Private Sub Command1_Click()
Dim i As Integer
i = Text1.Text
If i Mod 2 = 0 Then
MsgBox "偶数"
Else
MsgBox "奇数"
End If
End Sub