首页 > 其他 > 详细

for循环输出菱形

时间:2016-02-26 17:09:34      阅读:301      评论:0      收藏:0      [点我收藏+]
package com.hanqi;

public class lingxing {

    public static void main(String[] args) {

        for(int m=1;m<=10;m++)
        {
            //输出空格
            for(int n=9;n>=m;n-- )
              {
                System.out.print(" ");
              }    
            
            //输出*
            for(int n=1;n<=m;n++)
                {
                  System.out.print("*");
                }
            
            for(int n=1;n<m;n++)
                 {
                    System.out.print("*");
                 }
                System.out.println(" ");
        }
                
        for(int m=1;m<=9;m++)
        {
            //输出空格
            for(int n=1;n<=m;n++ )
              {
                System.out.print(" ");
              }    
            
            //输出*
            for(int n=9;n>=m;n--)
              {
                System.out.print("*");
              }
            for(int n=9;n>m;n--)
              {
                System.out.print("*");
              }
            
            System.out.println(" ");
        }
    
    
    }

}

技术分享

for循环输出菱形

原文:http://www.cnblogs.com/wangchuanqi/p/5220832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!