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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

共享一下,效果图如下:
两遍是循环, 中间是随机。
死循环

360反馈意见截图16581121115123113.png (30.81 KB, 下载次数: 7)

360反馈意见截图16581121115123113.png

3 个回复

倒序浏览
代码如下
class Demo9 {
        public static void main (String[] args) {
                int a = 30 ;
                int b = 0 ;
                int e = 0;
                int n = 1;
                double d ;
                int r;
                int c = 7;
                boolean bl = true;
                boolean bt = true;
                while (bt) {       
                        n++;
                        if (n==0) {
                                bt= false;
                        }
                        d = Math.random();
                        r = (int)(d*10);
                        if (d > 0.5) {
                                a+=1;
                                if (a > 60) {
                                        a=60;
                                }
                        } else {
                                a-=1;
                                if (a < 1) {
                                        a = 1 ;
                                }
                        }
                        c++;
                        if (c == 7) {
                                bl = !bl;
                        }
                        c%=7;
                       
                        e = 7-c;

                       
                       
                        if (bl) {
                       
                                for (int c2 = 0; c2 < e ; c2++ ) {
                                        System.out.print(" ");       
                                }
                                System.out.print("*");
                                for (int c1 = 0; c1 < c ; c1++ ) {
                                        System.out.print(" ");
                                }
                        } else {
                               
                                for (int c1 = 0; c1 < c ; c1++ ) {
                                        System.out.print(" ");
                                }
                                System.out.print("*");
                                for (int c2 = 0; c2 < e ; c2++ ) {
                                        System.out.print(" ");       
                                }       
                        }
                       
                        System.out.print(r);
                        for ( int i = 0; i < a ; i++ ) {
                                System.out.print(" ");
                        }
                        System.out.print("*");
                        b = 60-a;
                        for ( int j = 0;j < b  ; j++ ) {
                                System.out.print(" ");
                        }
                        System.out.print(9-r);

                        if (bl) {               
                                for (int c1 = 0; c1 < c ; c1++ ) {
                                        System.out.print(" ");
                                }
                                System.out.println("*");
                        } else {
                                for (int c2 = 0; c2 < e ; c2++ ) {
                                        System.out.print(" ");       
                                }
                                System.out.println("*");
                        }
                                               
                }

        }
}
回复 使用道具 举报
哇,好复杂,都运用了那方面的知识啊
回复 使用道具 举报
喝咖啡的玉米 发表于 2016-9-24 22:06
哇,好复杂,都运用了那方面的知识啊

这几天学的知识。。for循环和if语句什么的
   自习课就干了这个…  
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马