编写applet程序,打印下面的菱形形状。最大限度地利用循环结构,并最大限度地减少输出语句。
                                  *
                              ***
                             *****
                            *******
                           *********
                            *******
                             *****
                              ***
                               *

解决方案 »

  1.   

    这里是一个applet程序,要用到坐标来定位,所以循环中只判断开始位置好象不是行吧?
      

  2.   

    哥们,你还真走运,我有个朋友前2天才问我同样的这个问题,他要求一个循环搞定。正好现在贴出来给你
    String  prit = "*";
    int     max  = 19;
    int     col  = max;
    int  step = 2;
    for (int starts = 1,row=1;row<= max;starts++) {
    if(starts<(col/2)+1||starts>(max-(col/2))){
    System.out.print(" ");
    }else{
    System.out.print(prit);
    }
    if(starts==max){
    col    = col-step;
    starts = 0;
    step   = ((++row!=(max/2+1))?step:-step);
    System.out.println();
    }
    }
      

  3.   

    这个确实不错~~
    但是我这个题目是做applet程序的啊`~不是应用程序。
      

  4.   

    private String   prit = "*";
    private int     max  = 19;
    private int     col  = max;
    private int  step = 2;

    public void paint(Graphics g) {
    int xpos =100;
    int ypos =100;
    for (int starts = 1,row=1;row<= max;starts++) {
    if(starts<(col/2)+1||starts>(max-(col/2))){
    //System.out.print(" ");
    xpos = xpos+5;
    }else{
    //System.out.print(prit);
    g.drawString(prit,xpos,ypos);
    xpos = xpos+5;
    }
    if(starts==max){
    col    = col-step;
    starts = 0;
    step   = ((++row!=(max/2+1))?step:-step);
    //System.out.println();
    ypos   =ypos+10;
    xpos   =100;
    }
    }
    }