English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問要如何寫出一大 5 之正整數 n,印出如下由星號(*)組成之正方形圖形。該正方形之邊長為 n,且第 i 列之第 i 行亦有一星號?

2006-04-17 21:58:38 · 1 個解答 · 發問者 ? 1 in 電腦與網際網路 軟體

1 個解答

用什麼語言寫呢?

2006-04-18 11:19:46 補充:
vb:
Dim num_s As String
Dim inum As Integer

Private Sub Form_Activate()
Do
num_s = InputBox("請輸入一個大於5的整數:", "輸入方塊")
inum = Val(num_s)
Loop While (inum < 5)
Call prtstar(inum)
Call spacestar(inum - 2)
Call prtstar(inum)

End Sub


Public Sub prtstar(num As Integer)
For i = 1 To num
Print "*"
Next i
Print
End Sub



Public Sub spacestar(num As Integer)
For i = 1 To num
Print "*"
For j = 1 To i - 1
Print " "
Next j

Print "*"

For k = 1 To num - i
Print " "
Next k

Print "*": Print
Next i
End Sub

java:
import java.io.*;

class Rect
{
static void PrtStar(int num) //印出一行*號
{
for(int i=1;i<=num;i++)
System.out.print("*");
System.out.println();
}

static void SpaceStar(int num) //印出星號與空白
{
for(int i=1;i<=num;i++)
{
System.out.print("*");

for(int j=1;j<=i-1;j++)
System.out.print(" ");

System.out.print("*");

for(int k=1;k<=num-i;k++)
System.out.print(" ");
System.out.println("*");
}
}
}

public class normal_94_01
{
public static void main(String args[]) throws IOException
{
BufferedReader num_s;
num_s = new BufferedReader(new InputStreamReader(System.in));

int inum;
do
{
System.out.print("請輸入一個大於5的整數:");
inum = Integer.parseInt(num_s.readLine());
}while(inum<5);

Rect.PrtStar(inum);
Rect.SpaceStar(inum-2);
Rect.PrtStar(inum);

}
}

2006-04-18 07:19:46 · answer #1 · answered by 上官 5 · 0 0

fedest.com, questions and answers