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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 小小M 中级黑马   /  2016-4-25 22:39  /  784 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

打印等边三角形(题目较难,可作为扩展)
                    *
                   * *
                  * * *
                 * * * *

这是我们今天的作业题,虽然是扩展题
但是也是想把它做出来的
欢迎懂的大神给段代码

5 个回复

倒序浏览
打印的时候for循环打空格
回复 使用道具 举报
打印的时候for循环打空格
回复 使用道具 举报
for (int i = 0;i <= 9 ;i++ ) {
                                for (int j = i;j <= 0 ;j++ ) {
                                        System.out.print(" ");

                                }
                                for (int h = 0;h < 1 + i * 2 ;h++ ) {
                                        System.out.print("*");
                                }
                                System.out.println();
                        }
回复 使用道具 举报
import java.util.Scanner;
class XingXing {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入一个正整数,强力建议3~20");
                int z = sc.nextInt();
                if (z > 0) {
                        for (int h = 1;h <= z ;h++ ) {
                                xing(h,z);
                        }
                }else
                        System.out.println("你逗老子");       
        }

        public static void xing(int h,int z) {
                int b = h;
                while ( b > 1 ) {
                        System.out.print(" ");
                        b--;
                }
                for (int a = z + 1 - h;a > 0 ;a-- ) {
                        System.out.print("*" + " ");
                }
                System.out.println();
        }

}

倒三角
回复 使用道具 举报
Scanner sca = new Scanner(System.in);                 System.out.println("请输入几边三角形");                 int num = sca.nextInt();                 for (int i = 0; i < num; i++) {                         for (int j =0 ; j < num - i; j++) {                                 System.out.print(" ");                         }                         for (int k = 0; k < i + 1; k++) {                                 System.out.print("* ");                         }                         System.out.println();                 }
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马