java 打印各种 图形

  1. <pre code_snippet_id="94876" snippet_file_name="blog_20131203_1_8551646" name="code" class="java">package ch09;  
  2.   
  3. import java.util.Scanner;  
  4.   
  5. public class Test03  
  6. {  
  7.     public static void main(String[] args)  
  8.     {  
  9.         Scanner input = new Scanner(System.in);  
  10.         System.out.println("请输入行数");  
  11.         int rows=input.nextInt();  
  12.         for (int i = 0; i < rows; i++)  
  13.         {  
  14.             for (int j = 0; j <= i; j++)  
  15.             {  
  16.                 System.out.print("* ");  
  17.             }  
  18.             System.out.println();  
  19.         }  
  20.         System.out.println("倒过来的三角");  
  21.         for (int i = rows-1; i >=0; i--)  
  22.         {  
  23.             for (int j = 0; j <= i; j++)  
  24.             {  
  25.                 System.out.print("* ");  
  26.             }  
  27.             System.out.println();  
  28.         }  
  29.           
  30.     }  
  31. }  
  32. 请输入行数  
  33. 5  
  34. *   
  35. * *   
  36. * * *   
  37. * * * *   
  38. * * * * *   
  39. 倒过来的三角  
  40. * * * * *   
  41. * * * *   
  42. * * *   
  43. * *   
  44. *   
  45. </pre><br>  
  46. <pre code_snippet_id="94876" snippet_file_name="blog_20131203_2_2062106" name="code" class="java">package ch09;  
  47.   
  48. import java.util.Scanner;  
  49.   
  50.   
  51.   
  52. public class Test04  
  53. {  
  54.     public static void main(String[] args)  
  55.     {  
  56.         Scanner input = new Scanner(System.in);  
  57.         System.out.println("请输入行数");  
  58.         int row=input.nextInt();  
  59.           
  60.         for (int i = 1; i <=row; i++)  
  61.         {  
  62.             for (int j = 0; j < row-i; j++)  
  63.             {  
  64.                 System.out.print(" ");  
  65.             }  
  66.             for (int j = 0; j < 2*i-1; j++)  
  67.             {  
  68.                 System.out.print("*");  
  69.             }  
  70.             System.out.println();  
  71.         }  
  72.            
  73.           
  74.     }  
  75. }  
  76. 请输入行数  
  77. 10  
  78.          *  
  79.         ***  
  80.        *****  
  81.       *******  
  82.      *********  
  83.     ***********  
  84.    *************  
  85.   ***************  
  86.  *****************  
  87. *******************  
  88. </pre><br>  
  89. <pre code_snippet_id="94876" snippet_file_name="blog_20131203_3_6347484" name="code" class="java">package ch09;  
  90.   
  91. import java.util.Scanner;  
  92.   
  93. public class Test05  
  94. {  
  95.     public static void main(String[] args)  
  96.     {  
  97.         Scanner input = new Scanner(System.in);  
  98.         int row = 0;  
  99.         System.out.println("请输入行数");  
  100.         row = input.nextInt();  
  101.          while (row%2==0){  
  102.              System.out.println("请输入奇数");  
  103.              row=input.nextInt();  
  104.          }  
  105.   
  106.         for (int i = 1; i <= row; i++)  
  107.         {  
  108.             for (int j = 0; j < row - i; j++)  
  109.             {  
  110.                 System.out.print(" ");  
  111.             }  
  112.             for (int j = 0; j < 2 * i - 1; j++)  
  113.             {  
  114.                 System.out.print("*");  
  115.             }  
  116.             System.out.println();  
  117.         }  
  118.         for (int i = row-1; i >=0; i--)  
  119.         {  
  120.             for (int j = 0; j < row - i; j++)  
  121.             {  
  122.                 System.out.print(" ");  
  123.             }  
  124.             for (int j =2 * i - 1;j>0 ; j--)  
  125.             {  
  126.                 System.out.print("*");  
  127.             }  
  128.             System.out.println();  
  129.         }  
  130.   
  131.   
  132.     }  
  133. }  
  134. </pre><br>  
  135. <pre code_snippet_id="94876" snippet_file_name="blog_20131203_4_1189271" name="code" class="java">请输入行数  
  136. 7  
  137.       *  
  138.      ***  
  139.     *****  
  140.    *******  
  141.   *********  
  142.  ***********  
  143. *************  
  144.  ***********  
  145.   *********  
  146.    *******  
  147.     *****  
  148.      ***  
  149.       *  
  150.          
  151. </pre><br>  
  152. <pre code_snippet_id="94876" snippet_file_name="blog_20131203_5_3555822" name="code" class="java">package ch09;  
  153.   
  154. import java.util.Scanner;  
  155.   
  156. public class Test06  
  157. {  
  158.     public static void main(String[] args)  
  159.     {  
  160.         Scanner input = new Scanner(System.in);  
  161.         int count = 0;  
  162.         System.out.println("请输入边长");  
  163.         count=input.nextInt();  
  164.         // 控制行数  
  165.         for (int i = 0; i < count; i++) {  
  166.             if (i == 0 || i == count - 1) {  
  167.                 // 数组第一个行和最后一行的边  
  168.                 for (int j = 0; j < count; j++) {  
  169.                     System.out.print("* ");  
  170.                 }  
  171.             } else {  
  172.                 // 左边的边  
  173.                 System.out.print("*");  
  174.                 // 输出空格  
  175.                 for (int j = 0; j < count - 2; j++) {  
  176.                     System.out.print("  ");  
  177.                 }  
  178.                 // 右边的边  
  179.                 System.out.print(" *");  
  180.             }  
  181.             // 换行  
  182.             System.out.println();  
  183.         }  
  184.           
  185.     }  
  186. }  
  187. 请输入边长  
  188. 10  
  189. * * * * * * * * * *   
  190. *                 *  
  191. *                 *  
  192. *                 *  
  193. *                 *  
  194. *                 *  
  195. *                 *  
  196. *                 *  
  197. *                 *  
  198. * * * * * * * * * * </pre><br>  
  199. package ch09;

  200. public class Test02{
  201. public static void main(String[] args){
  202. for (int i = 0; i < 13; i++){
  203. for (int j = 0; j <= i; j++){
  204. System.out.print("* ");
  205. }
  206. System.out.println();
  207. }
  208. }
  209. }

  210. * * 
    * * * 
    * * * * 
    * * * * * 
    * * * * * * 
    * * * * * * * 
    * * * * * * * * 
    * * * * * * * * * 
    * * * * * * * * * * 
    * * * * * * * * * * * 
    * * * * * * * * * * * * 
    * * * * * * * * * * * * * 
  211. <pre></pre>  
  212. <pre></pre>  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值