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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王龙 中级黑马   /  2012-10-24 19:23  /  2330 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

今天,饭后一练,选择的是打印一个平行四边形,突然间有了这个想法,想的大半天,没想出来,请教,希望给出代码,表示感谢
(注:中问那个菱行是空的,周边四个平等四边形是用"*"打印的)

无标题.png (9.22 KB, 下载次数: 20)

无标题.png

评分

参与人数 1技术分 +1 收起 理由
谭立文 + 1 淡定

查看全部评分

4 个回复

倒序浏览
  1. class  Tu
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 int[] h = new int[10];
  6.         for(int i=0 ;i<h.length;i++)
  7.                 {
  8.             for(int j=0;j<h.length-i;j++)
  9.                                 {
  10.                 System.out.print(" ");               
  11.                 }
  12.             for(int m=0; m<h.length;m++)
  13.                                 {
  14.                 System.out.print("*");
  15.                 }
  16.    
  17.          
  18.             for(int b=0;b<2*(i+1)-1;b++){
  19.                 System.out.print(" ");        
  20.             }
  21.             for(int c=0;c<h.length;c++){
  22.                 System.out.print("*");
  23.             }

  24.                         System.out.println();
  25.                 }
  26.       

  27.                         int[] d = new int[10];
  28.                         for(int i=0;i<d.length;i++)
  29.                         {
  30.                                 for(int j=0;j<i;j++)
  31.                                         {
  32.                                         System.out.print(" ");               
  33.                                         }
  34.                                 for(int m=0;m<d.length;m++)
  35.                                         {
  36.                                         System.out.print("*");
  37.                                         }   
  38.                                 for(int m=0;m<2*(d.length-i)-1;m++)
  39.                                         {
  40.                                         System.out.print(" ");
  41.                                         }
  42.                                 for(int c=0;c<h.length;c++)
  43.                                         {
  44.                                         System.out.print("*");
  45.                                         }

  46.                                 System.out.println();
  47.                         }
  48.         }
  49.         

  50.                
  51.                
  52.        
  53. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
谭立文 + 1

查看全部评分

回复 使用道具 举报
默默地画了一晚上...
刚开始学就只能写成这样,不知道以后还会有什么好办法- -
回复 使用道具 举报
杨雪松 发表于 2012-10-24 21:53
默默地画了一晚上...
刚开始学就只能写成这样,不知道以后还会有什么好办法- - ...

表示非常感谢
回复 使用道具 举报
  1. class PrintDiamond
  2. {public static void main(String[] args)
  3. {char[][] a = new char[20][40];//存图形
  4. int i,j;
  5. for(i=0;i<10;i++)
  6. for(j=0;j<40;j++)
  7. { if(j<=10)
  8. a[i][j]=(i<=10-j)?' ':'*';//将图形上半部分,分成四块存储
  9. if(j>10 &&j<=20)
  10. a[i][j]=(i<=20-j)?'*':' ';
  11. if(j>20 &&j<=30)
  12. a[i][j]=(i+20<=j)?'*':' ';
  13. if(j>30 &&j<=40)
  14. a[i][j]=(i+30<=j)?' ':'*';
  15. a[20-i-1][j]=(a[i][j]==' ')?' ':'*';//根据上下对称,存储图形下半部分
  16. }
  17. for(i=0;i<20;i++)//输出图形
  18. System.out.println(a[i]);
  19. }
  20. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
古银平 + 1 赞一个!

查看全部评分

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