【发布时间】:2014-12-10 22:21:02
【问题描述】:
我正在尝试创建一个绘制一系列空格和星号的子过程,然后输出结果。用户输入他们想要的星星数量和空间数量,然后输出在屏幕上绘制的星星和空间。例如,DrawStars(4,5) 将输出 ----*****。
到目前为止,这是我的代码:
Module Module1
Sub Main()
Dim Spaces As Integer = 0
Dim Stars As Integer = 0
Dim TotalChars As Integer = 0
Console.WriteLine("Enter the number of spaces you want to enter")
Spaces = Console.ReadLine
Console.WriteLine("Enter the number of stars you want to enter")
Stars = Console.ReadLine
TotalChars = Spaces + Stars
DrawStars(Spaces, Stars, TotalChars)
Console.WriteLine("")
Console.ReadLine()
End Sub
Sub DrawStars(ByVal Spaces As Integer, ByVal Stars As Integer, ByVal TotalChars As Integer)
Dim Output As String
Do Until TotalChars = Stars + Spaces
If Spaces > 0 The
Output = Console.ReadLine
Else
Console.WriteLine("*")
End If
Loop
End Sub
结束模块
【问题讨论】:
-
你需要 2 个 For 循环,一个用于空格数,一个用于星号,只需将它们添加到相同的输出变量中即可;它不需要
totalchars
标签: vb.net visual-studio-2010 visual-studio visual-studio-2008