用math.abs打印菱形

解决方案 »

  1.   

    public class Untitled1 
    {
       public static void main(String args[]) 
       {
        int line = Integer.parseInt(args[0]);
        int n = -line;
         do {
              show(Math.abs(n),' ');
              show((line-Math.abs(n))*2+1,'*');
              System.out.println();
                n++;
         }while (n<=line);
    }
     public static void show(int i,char c)
      {
         for (int n = 0;n<i;n++) 
          {
            System.out.print(c);
          }
       }
    }