}
}
}
输出结果是:
A
AA
AAA
AAAA
AAAAA
要是我想把图形变成,
A
AA
AAA
AAAA
AAAAA
AAAA
AAA
AA
A
怎么写循环呢,谢谢大家了。。 作者: 黄燕京 时间: 2012-5-6 16:09
public class lingxing
{
public static void main(String[] args) {
final int size = 4;
for (int i = 1; i <= size; i++) {
for (int j = i; j < size; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("A");
}
System.out.println();
}
for (int i = size - 1; i >= 1; i--) {
for (int j = 1; j <= size - i; j++) {
System.out.print(" ");
}
for (int k = 2 * i - 1; k > 0; k--) {
System.out.print("A");
}
System.out.println();
}
}
}作者: 徐慧书 时间: 2012-5-6 16:13
哥们,这种程序还是得多写啊:
上代码了:
public class Test {
public static final char CH = 'A';
public static final int LEVEL = 5;
public static void main(String[] args) {
for (int j = 1; j <= LEVEL; j++) {
print(LEVEL - j, j);
}
for (int k = LEVEL - 1; k >= 1; k--) {
print(LEVEL - k, k);
}
}
public static void print(int m, int n)//打印一行 m表示要打印的空格数,n表示要打印的字符个数
{
//如果想要距离左边有空的话,就在这打印空格
for(int i = 0 ; i < m; i ++)
System.out.print(' ');
for(int j = 0 ; j < n; j++)
{
System.out.print(CH);
System.out.print(' ');
}
System.out.println();
}
}