DEV Community

Guna Sekaran
Guna Sekaran

Posted on

1

Java Programs for Alphabet And Pattern Printing

  package ifelse;

public class Patter_n {
    public static void main(String[] args) {

        pattern_x();

    }
    public static void pattern_x() 
    {
            for(int row=1;row<=9;row++)
            {
                for(int col=1;col<=9;col++)
                {
                    if(row==col || row+col==10) {
                        System.out.print("* ");
                    }
                    else {
                        System.out.print("  ");
                    }

                }

                System.out.println();

            }
    }  

.........................................................................

   OUTPUT:

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



Enter fullscreen mode Exit fullscreen mode
package ifelse;

public class Patter_n {
    public static void main(String[] args) {

//      pattern_x();
        pattern();

    }
    private static void pattern() {
        // TODO Auto-generated method stub
        for(int row=1;row<=9;row++)
        {
            for(int col=1;col<=9;col++) {

                if(col==1 ||col==9 ||row==col || row+col==10) {
                    System.out.print("* ");
                    }
                else {
                    System.out.print("  ");
                }
                }

                System.out.println();   

        }
        }

.........................................................................

OUTPUT:
*               * 
* *           * * 
*   *       *   * 
*     *   *     * 
*       *       * 
*     *   *     * 
*   *       *   * 
* *           * * 
*               * 


Enter fullscreen mode Exit fullscreen mode
package ifelse;

public class Patter_n {
    public static void main(String[] args) {

//      pattern_x();
        pattern();

    }
    private static void pattern() {
        // TODO Auto-generated method stub
        for(int row=1;row<=9;row++)
        {
            for(int col=1;col<=9;col++) {

                if( col==5 ||row==5 ||row==col || row+col==10) {
                    System.out.print("* ");
                    }
                else {
                    System.out.print("  ");
                }
                }

                System.out.println();   

        }
}

.........................................................................

OUTPUT:

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

Enter fullscreen mode Exit fullscreen mode
package ifelse;

public class Patter_n {
    public static void main(String[] args) {

//      pattern_x();
//      pattern();
        pattern_c();


    }
    private static void pattern_c() {
        // TODO Auto-generated method stub



        for(int row=1;row<=9;row++)
        {
            for(int col=1;col<=9;col++) {

                if(col==1 ||row==1 ||row==9 ) {
                    System.out.print("* ");
                    }
                else {
                    System.out.print("  ");
                }
                }

                System.out.println();   

        }



    }

.........................................................................
   OUTPUT:
* * * * * * * * * 
*                 
*                 
*                 
*                 
*                 
*                 
*                 
* * * * * * * * * 

Enter fullscreen mode Exit fullscreen mode
package ifelse;

public class Patter_n {
    public static void main(String[] args) {

//      pattern_x();
//      pattern();
        pattern_c();


    }
    private static void pattern_c() {
        // TODO Auto-generated method stub



        for(int row=1;row<=9;row++)
        {
            for(int col=1;col<=9;col++) {

                if(col==5||row==1 ||row==9 ) {
                    System.out.print("* ");
                    }
                else {
                    System.out.print("  ");
                }
                }

                System.out.println();   

        }



    }
.........................................................................
    OUTPUT:
* * * * * * * * * 
        *         
        *         
        *         
        *         
        *         
        *         
        *         
* * * * * * * * * 

Enter fullscreen mode Exit fullscreen mode

public class Patter_n {
    public static void main(String[] args) {

//      pattern_x();
//      pattern();
        pattern_c();


    }
    private static void pattern_c() {
        // TODO Auto-generated method stub



        for(int row=1;row<=9;row++)
        {
            for(int col=1;col<=9;col++) {

                if(col==1 ||col==9 ||row==col ) {
                    System.out.print("* ");
                    }
                else {
                    System.out.print("  ");
                }
                }

                System.out.println();   

        }



    }
.........................................................................
      OUTPUT:
*               * 
* *             * 
*   *           * 
*     *         * 
*       *       * 
*         *     * 
*           *   * 
*             * * 
*               * 

Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay