好吧,我试图完成一个挑战,要求我从 0 到 1000 获得所有 5 或 3 的倍数,然后得到它们的总和,我是 vb.net 的新手,所以我认为这将是一个不错的选择我要解决的挑战> 我很确定我的基础知识是正确的,但我不太确定为什么会出现这个错误:/。
Module Module1
Sub Main()
Dim Counter As Integer = 1
Dim Numbers() As Integer
Dim NumbersCounter As Integer = 0
Dim Total As Integer = 0
While (Counter <= 1000)
If (Counter Mod 3 = 0) Then
Numbers(NumbersCounter) = Counter '<--- The error is located on Numbers.
NumbersCounter = NumbersCounter + 1
Counter = Counter + 1
ElseIf (Counter Mod 5 = 0) Then
Numbers(NumbersCounter) = Counter
NumbersCounter = NumbersCounter + 1
Counter = Counter + 1
Else
Counter = Counter + 1
End If
End While
Counter = 0
While (Counter <= Numbers.Length)
If (Counter = 0) Then
Total = Numbers(Counter)
Counter = Counter + 1
Else
Total = Total * Numbers(Counter)
Counter = Counter + 1
End If
End While
PrintLine(Total)
End Sub
End Module
任何帮助或提示将不胜感激!提前致谢。