请教VB.NET实现输出实心菱形!谢谢!
****
*****
*******
*********
*******
*****
***
*
显示效果如上! --------------------编程问答-------------------- 有书,可以查。
好像用两个for就可以搞定。当年学c的时候就有教过啊。呵呵。
public sub PrintSling( MaxX as integer)
dim i as integer
'写菱形的上半部分:
for i= 1 to MaxX
debug.print("星号"*i) '生成或者格式出星号字符串跟i有关系,具体细化自己写或查书。
next
'写菱形的上半部分:
for i =MaxX-1 to 1 step -1
debug.print("星号"*i) '生成星号字符串,从做多个减少到一个。
Next
end sub
----
另外就是可以生产上半部分菱形。下半部分就可以用上半部分颠倒一下,就可以搞定。
--------------------编程问答--------------------
Public Class Form1--------------------编程问答-------------------- --------------------编程问答-------------------- 呵呵 这是国家2级VB 的上机题目
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
iDraw(120, 100, 4)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Show()
Dim i As Integer
Dim x As Double = 120
Dim y As Double = 50
For i = 1 To 17 Step 2
iDraw(x, y, i)
x = x - 9
y = y + 9
Next
x = x + 15
For i = 15 To 1 Step -2
iDraw(x, y, i)
x = x + 9
y = y + 9
Next
End Sub
Private Sub iDraw(ByVal x As Double, ByVal y As Double, ByVal k As Integer)
Dim g As Graphics = Me.CreateGraphics()
Dim i As Integer
Dim x1 As Double = x
' Dim y1 As Double = y
For i = 1 To k
g.DrawString("*", Me.Font, Brushes.Green, x1, y)
x1 = x1 + 9
Next
End Sub
End Class
其实很简单
补充:.NET技术 , VB.NET