java面试每日一题12

题目:打印出如下图案(菱形)
    *
   ***
 ******
********
 ******
  ***
   *

public class Diamond {
    public static void main(String[] args){
        System.out.println("实心菱形:");  
        int hangshu=5;
         for(int i = 0; i < hangshu - 1; i++) 
            { 
                for(int x = i + 1; x < hangshu; x++) 
                { 
                    System.out.print("&"); 
                } 
                for(int y = 0; y < (i + 1) * 2 - 1; y++) 
                { 
                    System.out.print("*"); 
                } 
                System.out.println(); 
            }
         for(int i=hangshu-3;i>=0;i--){
             for(int x = i ; x < hangshu-1; x++) 
                { 
                    System.out.print("&"); 
                } 
                for(int y = 0; y < (i + 1) * 2 - 1; y++) 
                { 
                    System.out.print("*"); 
                } 
                System.out.println(); 
         }
    }
}

 

posted @ 2016-10-14 17:12  那一年的我们  阅读(156)  评论(0编辑  收藏  举报