Topic: 帮忙看一下( 怎样输出下面的三角图形)

  Print this page

1.帮忙看一下( 怎样输出下面的三角图形) Copy to clipboard
Posted by: manwubianji
Posted on: 2006-06-17 21:35

怎样输出下面的图形

*
* * *
* * * * *
* * * * * * *

小弟先谢谢了

2.Re:帮忙看一下 [Re: manwubianji] Copy to clipboard
Posted by: xiaosilent
Posted on: 2006-06-17 22:25

public class Demo{
public static void main(String[] args){
System.out.println("*");
System.out.println("***");
System.out.println("*****");
System.out.println("*******");
}
}

这样?StupidStupidStupid

3.Re:帮忙看一下 [Re: manwubianji] Copy to clipboard
Posted by: Skybus
Posted on: 2006-06-18 00:16

好像是要求使用循环吧

4.Re:帮忙看一下( 怎样输出下面的三角图形) [Re: manwubianji] Copy to clipboard
Posted by: hailang1986
Posted on: 2006-06-18 20:22

2楼的方法是可行的,也是最简单的。

5.Re:帮忙看一下( 怎样输出下面的三角图形) [Re: manwubianji] Copy to clipboard
Posted by: oujianqiang
Posted on: 2006-06-18 20:23

从控制台输入要打印的行数,而每一行的*怯是一个等差数列,求出通项,就可以解决了

6.Re:帮忙看一下( 怎样输出下面的三角图形) [Re: manwubianji] Copy to clipboard
Posted by: sunjavaduke
Posted on: 2006-06-19 16:59

用个循环应该就可以了
二楼的效率不好

7.Re:帮忙看一下( 怎样输出下面的三角图形) [Re: sunjavaduke] Copy to clipboard
Posted by: why
Posted on: 2006-06-20 19:40

sunjavaduke wrote:
二楼的效率不好

What did you mean?
效率好? something like
System.out.println("*\n***\n*****\n*******");
Wink


oujianqiang wrote:
从控制台输入要打印的行数,而每一行的*怯是一个等差数列,求出通项,就可以解决了

What is 怯 in 每一行的*怯是一个等差数列?


A solution for you to start with:

void printTriangle(int numLevels) {
for (int i = 1; i <= numLevels; i++) {
// print the leading spaces
for (int j = 1; j <= (numLevels - i); j++) {
System.out.print(" ");
}
// print the asterisks
for (int j = (numLevels - (i - 1)); j <= (numLevels + (i - 1)); j++) {
System.out.print(" *");
}
// newline (level)
System.out.println();
}
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923