level 4
Private Function SXH() As List(Of Integer)
Dim list As New List(Of Integer)
For n As Integer = 100 To 999
If n = CInt(n.ToString.Substring(0, 1)) ^ 3 + CInt(n.ToString.Substring(1, 1)) ^ 3 + CInt(n.ToString.Substring(2, 1)) ^ 3 Then
list.Add(n)
End If
Next
Return list
End Function
上面的函数返回100-999内的水仙花数的集合
Private Sub btnclick() Handles Button3.Click
For Each n As Integer In SXH()
Console.Write(n)
Console.Write(vbCrLf)
Next
End Sub
用按钮测试,在输出框显示

