A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yw201605 中级黑马   /  2016-7-2 22:55  /  662 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class Demo2_While {
        public static void main(String[] args) {
                //求1到100的和;
                /*int i = 1;
                int count = 0;
                while (i <= 100) {
                        count += i;
                        i ++;   //让变量i自增
                        }
                System.out.println("count=" + count);*/





        /*for (int x =1;x <= 4 ;x ++ ) {
                for (int y =1;y <= 5 ;y ++ ) {
                        System.out.print("*");
                }
                        System.out.println();
                }*/


                //用while语句计算1到100的偶数,奇数和;
                /*int sum = 0;
                  int sun = 0;
                  int x = 1;
                  while (x <= 100) {
                                if (x % 2 ==0) {
                                sum += x;
                        } else {
                            sun += x;
                        }
                                x ++;
                        }
                        System.out.println("sum=" + sum + ",sun=" + sun);*/



                        //用do while 语句计算1到100的偶数,奇数和;
                       
                        /*int x = 1;
                        int sum = 0;
                        int sun = 0;
                        do {
                                if (x % 2 == 0) {
                                        sum += x;
                                } else {
                                        sun += x;
                                }
                                        x ++;
                                }
                                while (x <= 100);
                                System.out.println("sum="+ sum + ",sun=" + sun);*/


                        //输出一个直角三角形;
                        /*for (int i = 1;i <= 5 ;i++ ) {
                                for (int j = 1;j <=i ;j++ ) {
                                        System.out.print("*");
                                }
                                        System.out.println();
                                }*/



                        int i = 1;
                        int j = 1;
                        while (i <=5) {
                               

                                while (j <= i) {
                                        System.out.print("*");
                                }
                                i++;
                                j++;
                                }
                                        System.out.println();
                       







               
        }
}

8 个回复

倒序浏览
赞一个!!!1
回复 使用道具 举报
顶一个!
回复 使用道具 举报
很好,顶一个!
回复 使用道具 举报

{:3_57:}{:3_57:}{:3_57:}
回复 使用道具 举报

谢谢,
回复 使用道具 举报
66666666666666666666
回复 使用道具 举报
你带动我的心跳
回复 使用道具 举报
本帖最后由 wangyeake 于 2016-7-4 10:44 编辑

不错,不过我会把  System.out.println改为:System.out.print("/n");
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马