日期:2014-05-20  浏览次数:20570 次

怎样java语言编写小程序。
请问用java语言编写小程序,使输出结果为:
*
**
***
****
*****
代码怎样写?

------解决方案--------------------
嗯嗯 楼主 ,这个应该是课堂作业,代码写啦,分呢……
Java code

package test;

public class TestPrint {

    public static void main(String[] args) {
        String str = "*";
        String singleStr = "*";
        for (int i = 0; i < 5; i++) {
            System.out.println(str);
            str = str + singleStr;
        }
    }
}

------解决方案--------------------
Java code
public class PrintDemo {
    public static void main(String args[]) {
        for(int i=0;i<5;i++){
            for(int j=0;j<=i;j++){
                System.out.print("*");
            }
            System.out.println("");
        }
    }
}

------解决方案--------------------
Java code

    public static void main(String[] args) {
        String s = "*";
        for (int i = 0; i < 5; i++) {
            System.out.println(s);
            s=s+"*";
        }
    }

------解决方案--------------------
Java code
public class PrintAsterisk {

    /**
     * @param args
     */
    public static void main(String[] args) {
        for(int i = 0; i < 5; i++){
            for(int j = 0; j <= i; j++)
                System.out.print("*");
            System.out.println("");
        }
    }

}

------解决方案--------------------
LZ 一定要自己写,不会也要试着写。写几个就能发现差不多的规律,初学不难。不然到最后你会发现,自己动手能力很差,看着可能懂,但是写不出来。
我自己就吃过这方面的亏