DEV Community

Guna Sekaran
Guna Sekaran

Posted on

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

Top comments (0)