码迷,mamicode.com
首页 > 其他好文 > 详细

for循环输出菱形

时间:2016-02-26 17:09:57      阅读:162      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!