Computer Science, asked by Anonymous, 11 months ago

Give me program in java for printing a pattern of diamond.

Do with for-loop ONLY and ONLY scanner class

Answers

Answered by Anonymous
8

CODE :


class perfect_diamond

{

   void main()

   {

       System.out.println("           $");

       for(int a=1;a<=5;a++)

       {

           for(int b=5;b>=a;b--)

           {

               System.out.print("  ");

           }

           for(int c=1;c<=a;c++)

           {

               System.out.print('$'+" ");

           }

           for(int d=1;d<=a;d++)

           {

               System.out.print('$'+" ");

           }

           System.out.println();

       }

       System.out.println("$ $ $ $ $ $ $ $ $ $ $ $");

       

       for(int a=5;a>=1;a--)

       {

           for(int b=5;b>=a;b--)

           {

               System.out.print("  ");

           }

           for(int c=1;c<=a;c++)

           {

               System.out.print('$'+" ");

           }

           for(int d=1;d<=a;d++)

           {

               System.out.print('$'+" ");

           }

           System.out.println();

       }

       System.out.println("           $");

   }

}

       

NOTE :


⇒ Use n in place of 5 for printing n terms .

⇒ The pattern will be perfect  diamond and it is tested and verified in BlueJ.

⇒ Scanner class may or may not be used for updated compilers.

Similar questions