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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王海旺 中级黑马   /  2013-7-17 23:28  /  1723 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 杨兴庭 于 2013-7-18 18:08 编辑

左想右想 只想到这里 思路有些乱了 请大神们指教一下 麻烦将我的图形剩余部分显示出来(代码补全) 谢谢大家

  1. [img]C:\Documents and Settings\Administrator\桌面[/img]class Demo7
  2. {
  3.         public static void main(String[]args)
  4.         {
  5.                 for(int x=0;x<5;x++)
  6.                 {
  7.                         for(int y=x;y<5;y++)
  8.                         {
  9.                                 System.out.print(" ");
  10.                         }
  11.                         for(int z=0;z<=x;z++)
  12.                         {
  13.                                 if(z==0 || z==x)
  14.                                 {
  15.                                         System.out.print("* ");
  16.                                 }
  17.                                 else
  18.                                 {
  19.                                         System.out.print("  ");        
  20.                                 }
  21.                         }
  22.                         System.out.println();
  23.                 }
  24.                 for(int n = 1; n < 5; n++)
  25.                 {
  26.                         for(int m = 0; m <= n; m++)
  27.                         {
  28.                                 System.out.print(" ");
  29.                         }
  30.                         for(int a = n; a < 5; a++)
  31.                         {
  32.                                 if(a == n || a < n )
  33.                                 {
  34.                                         System.out.print("* ");
  35.                                 }
  36.                                 
  37.                                 
  38.                         }
  39.                         System.out.println();
  40.                 }
  41.         }
  42. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
杜光 + 1 每天提问并回答问题,是对知识的复习和积累.

查看全部评分

4 个回复

倒序浏览
本帖最后由 王广亚 于 2013-7-18 00:53 编辑
  1. package e1;


  2. public class Demo7
  3. {
  4.         public static void main(String[]args)
  5.         {
  6.                 for(int x=0;x<5;x++)
  7.                 {
  8.                         for(int y=x;y<4;y++)
  9.                         {
  10.                                 System.out.print(" ");
  11.                         }
  12.                         for(int z=0;z<=x;z++)
  13.                         {
  14.                                 if(z==0 || z==x)
  15.                                 {
  16.                                         System.out.print("* ");
  17.                                 }
  18.                                 else
  19.                                 {
  20.                                         System.out.print("  ");        
  21.                                 }
  22.                         }
  23.                         System.out.println();
  24.                 }
  25.                 for(int x=0;x<4;x++)
  26.                 {
  27.                         for(int y=0;y<=x;y++)
  28.                         {
  29.                                 System.out.print(" ");
  30.                         }
  31.                         for(int z=x;z<=3;z++)
  32.                         {
  33.                                 if(z==x || z==3)
  34.                                 {
  35.                                         System.out.print("* ");
  36.                                 }
  37.                                 else
  38.                                 {
  39.                                         System.out.print("  ");        
  40.                                 }
  41.                         }
  42.                         System.out.println();
  43.                 }
  44.         }
  45. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
杜光 + 1 每天提问并回答问题,是对知识的复习和积累.

查看全部评分

回复 使用道具 举报
// 精简版
public static void main(String[] args) {
                for (int i = 1; i <=9; i++) {
                        for (int j = 1; j <=9; j++) {
                               
                               
                                if(((i+j==6||i-j==4))||(j-i==4||i+j==14)){
                                       
                                System.out.print("*");
                               
                                }else {
                                        System.out.print(" ");
                                }
                        }
                        System.out.println();
                }
               
               
        }

评分

参与人数 1技术分 +1 收起 理由
杜光 + 1 每天提问并回答问题,是对知识的复习和积累.

查看全部评分

回复 使用道具 举报
  1. /*
  2.          打印空心菱形
  3.               --*       4   
  4.               -* *       3   5
  5.               *   *     2 6
  6.               -* * 4      
  7.               --*  5       *
  8.                                           * *
  9.                                          *   *
  10.                                         *     *
  11.                                          *   * 3  1
  12.                                           * *  2  2
  13.                                            *   1  3     *
  14.                                                                    * *
  15.                                                                   *   *
  16.                                                                  *     *
  17.                                                                 *       *
  18.                                                                  *     *
  19.                                                                   *   *
  20.                                                                    * *
  21.                                                                     *   
  22.          */
  23.         public static void printL(int x){
  24.                 //上半部分
  25.                 for(int i=1;i<=x/2+1;i++){
  26.                         for(int j=1;j<=(x/2+1)-i;j++){
  27.                                 System.out.print(" ");
  28.                         }
  29.                         for(int k=1;k<=i;k++){
  30.                                 if(k==1||k==i)
  31.                                         System.out.print("* ");
  32.                                 else
  33.                                         System.out.print("  ");
  34.                         }
  35.                         System.out.println();
  36.                 }               
  37.                 //下半部分
  38.                 for(int i=1;i<x/2+1;i++){
  39.                         for(int j=1;j<=i;j++){
  40.                                 System.out.print(" ");
  41.                         }
  42.                         for(int k=1;k<=(x/2+1)-i;k++){
  43.                                 if(k==1||k==(x/2+1)-i)
  44.                                         System.out.print("* ");
  45.                                 else
  46.                                         System.out.print("  ");
  47.                         }
  48.                         System.out.println();
  49.                 }
  50.         }
复制代码

评分

参与人数 1技术分 +1 收起 理由
杜光 + 1 每天提问并回答问题,是对知识的复习和积累.

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马