這個同時判定可以采用多線程做。但是一般都是使用數(shù)組循環(huán)來統(tǒng)計。
創(chuàng)新互聯(lián)專注于企業(yè)成都營銷網(wǎng)站建設、網(wǎng)站重做改版、鎮(zhèn)康網(wǎng)站定制設計、自適應品牌網(wǎng)站建設、H5技術、商城網(wǎng)站建設、集團公司官網(wǎng)建設、外貿網(wǎng)站建設、高端網(wǎng)站制作、響應式網(wǎng)頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為鎮(zhèn)康等各大城市提供網(wǎng)站開發(fā)制作服務。
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個數(shù)字中偶數(shù)有" n1 "個,奇數(shù)有" 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??"是偶數(shù)")
Else
MsgBox(a??"是奇數(shù)")
End?If
End?Sub
通過Abs()函數(shù)對整數(shù)取絕對值,然后通過Mod 2取余計算判斷,即除以2,余數(shù)是1,那么就是奇數(shù),余數(shù)是0就是偶數(shù)。如下:
If Abs(m) Mod 2 = 1 Then
Print m "是奇數(shù)"
Else
Print m "是偶數(shù)"
End If
Private Sub Command1_Click()
Dim i As Integer
i = Text1.Text
If i Mod 2 = 0 Then
MsgBox "偶數(shù)"
Else
MsgBox "奇數(shù)"
End If
End Sub