「VB.net」Modで偶数か奇数か判定する
書式
数値 Mod 2
使用例
Module Module1
Sub Main()
Dim num As Integer = 8
Dim num2 As Integer = 9
'関数funcAを呼び出す
funcA(num)
'関数funCAを呼び出す
funcA(num2)
Console.ReadKey()
End Sub
Sub funcA(ByVal num As Integer)
If num Mod 2 = 0 Then
Console.WriteLine(CStr(num) + "は偶数です")
Else
Console.WriteLine(CStr(num) + "は奇数です")
End If
End Sub
End Module
Module Module1
Sub Main()
Dim num As Integer = 8
Dim num2 As Integer = 9
'関数funcAを呼び出す
funcA(num)
'関数funCAを呼び出す
funcA(num2)
Console.ReadKey()
End Sub
Sub funcA(ByVal num As Integer)
If num Mod 2 = 0 Then
Console.WriteLine(CStr(num) + "は偶数です")
Else
Console.WriteLine(CStr(num) + "は奇数です")
End If
End Sub
End Module
Module Module1 Sub Main() Dim num As Integer = 8 Dim num2 As Integer = 9 '関数funcAを呼び出す funcA(num) '関数funCAを呼び出す funcA(num2) Console.ReadKey() End Sub Sub funcA(ByVal num As Integer) If num Mod 2 = 0 Then Console.WriteLine(CStr(num) + "は偶数です") Else Console.WriteLine(CStr(num) + "は奇数です") End If End Sub End Module
結果
8は偶数です
9は奇数です