用Java在控制台画一个菱形

二话不说,直接上代码:

package javaapplication2;
 
/**
 *
 * @author CodeMonkey
 */
public class JavaApplication2 {
 
    /**
     * @param jid the command line arguments
     */
       public static void main(String [] args)
    {
        JavaApplication2 Test = new JavaApplication2();
        if (args.length==0)
            Test.print(22);
        else
            Test.print(Integer.parseInt(args[0]));
    }
 
   public void print(int x) {
     for(int k = x >>> 1, i = -k; i <= k; i++) {
         System.out.print("			");
         for(int j = -k, m = k - Math.abs(i); j <= m; j++) {
             System.out.print(Math.abs(j) + Math.abs(i) == k || i * j == 0 ? '*' : ' ');
         }
         System.out.println();
     }
}
}
原文地址:https://www.cnblogs.com/liuxgnu/p/3535455.html