在vb.net中怎么编写一个控制台程序,求两个整数的平均值

来源:百度知道 编辑:UC知道 时间:2024/05/10 14:42:54
写代码

Sub Main()
Dim i, j As Integer
Dim tmpStr As String
Console.WriteLine("please input a integer")
tmpStr = Console.ReadLine()

If IsNumeric(tmpStr) And InStr(tmpStr, ".") < 1 Then
判断输入是否是整数,IsNumeric(tmpStr) 是判断是否是数字,InStr(tmpStr, ".")是判断是否有小数点.

i = CType(tmpStr, Integer)
Else
MsgBox("not a valid integer!")
Exit Sub
End If

Console.WriteLine("please input another integer")
tmpStr = Console.ReadLine()
If IsNumeric(tmpStr) And InStr(tmpStr, ".") < 1 Then
j = CType(tmpStr, Integer)
Else
MsgBox("not a valid integer!")
Exit Sub
End If

Console.WriteLine("the avg is : " & ((i + j) / 2).ToString & "press ente