微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

你怎么在vb.net中找到5个中最多的?

这是在3中找到最大值的代码,但我想找到最大值的代码5:

Dim a,b,c As Integer

a = InputBox("enter 1st no.") 
b = InputBox("enter 2nd no.") 
c = InputBox("enter 3rd no.")

If a > b Then 
    If a > c Then 
        MsgBox("A is Greater") 
    Else 
        MsgBox("C is greater") 
    End If 
Else 
    If b > c Then 
        MsgBox("B is Greater") 
    Else 
        MsgBox("C is Greater")
    End If 
End If

解决方法

正如大卫建议的那样,将您的值保存在列表中.这比使用单个变量更容易,并且可以扩展到所请求的数量(最多数百万个值).

如果由于某种原因需要保留单个变量,请执行以下操作:

Dim max As Integer = a
Dim name As String = "A"
If b > max Then
    max = b
    name = "B"
End If
If c > max Then
    max = c
    name = "C"
End If
If d > max Then
    max = d
    name = "D"
End If
' ...  extend to as many variables as you need.
MsgBox(name & " is greater")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐