Go to Top

Tuesday 2 August 2011

To print the given pattern

Question 28 : Write a program in Java to print the following pattern :

******
*      *
*      *
*      *
*      *
******

Java Program : 

public class pattern_15
{
 public static void main()
 {
     int  i,j;
     System.out.println("******");
     for(i=1;i<=4;i++)
     {
         System.out.print("*");
         for(j=1;j<=4;j++)
         {
             System.out.print(" ");
            }
            System.out.print("*");
            System.out.print("\n");
        }
        System.out.print("******");
    }
}

1 comment:

  1. I've got some good comments. Thank you all and please continue to share your views about improving this blog. This blog belongs not only to me but to you all, although I am its administrator.

    ReplyDelete

ShareThis