Visual studio 2010 如何使用循环反向获取值
问题在于我的代码的底部,我必须让程序以相反的顺序背诵输入的值。我想这可能和指数有关吧 选项显式打开 选项严格限制在 作者:默里·斯皮尔斯 日期:2012年10月12日 '编写一个接受五个输入值并将其存储到数组中的程序。 '然后按相反顺序显示数字。 '然后显示平均数,以及高于平均数的所有数字 导入系统 模块值Visual studio 2010 如何使用循环反向获取值,visual-studio-2010,variables,loops,Visual Studio 2010,Variables,Loops,问题在于我的代码的底部,我必须让程序以相反的顺序背诵输入的值。我想这可能和指数有关吧 选项显式打开 选项严格限制在 作者:默里·斯皮尔斯 日期:2012年10月12日 '编写一个接受五个输入值并将其存储到数组中的程序。 '然后按相反顺序显示数字。 '然后显示平均数,以及高于平均数的所有数字 导入系统 模块值 Sub Main() Dim Number(4) as Integer Dim Average as Double = 0 Dim Index as integer
Sub Main()
Dim Number(4) as Integer
Dim Average as Double = 0
Dim Index as integer
'
For Index = 0 to 4
Console.Write("Enter number: ")
Number(Index)=Convert.ToInt32(Console.Readline())
Next Index
'Figure out the average for all the entered values.
Average = (Number(0)+Number(1)+Number(2)+Number(3)+Number(4))/5
Console.Writeline("The average of the numbers is: " &Average)
Console.Write("Numbers that are greater than the average: ")
Index = 4
Do until Index = 0
If Number(Index) > Average then
Console.Writeline(Number(Index))
End If
Index -=1
Loop
Console.Writeline("Numbers in reverse order: ")
Index = 4
Do while Number(index) > 0
Console.Writeline(Number(Index))
Number(index) -= 1
Loop
End Sub
结束模块使用
步骤-1
向后退
For Index = 4 To 0 Step -1
' do your thing
Next
在我看来,最简单的方法就是使用一个循环,就像你输入数字时那样,但是当你自己写的时候,使索引反向运行。 这就是“第一步”的目的
逐行检查问题循环,注意变量值。是的,这对我有用!非常感谢。
For Index As Integer = 4 To 0 Step -1
Console.Writeline(Number(Index))
Next