DEV Community

hema latha
hema latha

Posted on • Edited on

For loop number patturn

public class Forloop {

    public static void main(String[] args) {



        pattern_n();
        pattern2();
        pattern3();
        pattern4();
        pattern5();
        pattern6();
        pattern7();
        pattern8();
        pattern9();
        pattern10();
        //patternN();
        //patternH();


        // TODO Auto-generated method stub      
}
    private static void pattern10() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            { 
if(col==1||col==4 ||col==9 ||line==1 && col>4 ||line==9 &&col>4 ) 
                System.out.print("* ");
            else {
                System.out.print("  ");
            }}
        System.out.println();
    }}
    private static void pattern9() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            { 
                if(line==1 ||col==1&&line<=5||line==5||col==9)
                    System.out.print("* ");
                else 
                    System.out.print("  ");
                            }
            System.out.println();
    }}
    private static void pattern8() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            { 
if(line==1  ||line == 9||line==5 || col==1 ||col==9)
                System.out.print("* ");
                else 
                    System.out.print("  ");

                }
                System.out.println();
            }
    }
    private static void pattern7() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
                if(line==1 ||col==9)
                {System.out.print("* ");
                }
                else {System.out.print("  ");
            }}
            System.out.println();
    }}
    private static void pattern6() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
    if (line==1 ||col ==1 ||line==9||line==5||col==9&&line>5)

            {System.out.print("* ");}
                else {
                    System.out.print("  ");}}
        System.out.println();
    }}
    private static void pattern5() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
if(line==1 || line==9 || line==5||col==9&& line>=6 || col==1 && line<=5)
                    {System.out.print("* ");}
                else {
                    System.out.print("  ");
            }}
                System.out.println();}
            }

    private static void pattern4() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
                if(col==1&&line<6||line==6|| col==5)
                    System.out.print("* ");
                else 
                    System.out.print("  ");
            }
                System.out.println();
            }
    }
    private static void pattern2() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
     if(line==1||col==9 && line<=5 ||line==5||line==9||col==1&& line>=5)
                    {System.out.print("* ");
                }
                else {
                    System.out.print("  ");}}
                    System.out.println();
    }}
    private static void pattern3() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
    if(line==1||line==9||line==5 ||col==9)
                System.out.print("* ");
            else 
                    if((col==1 && col>5) ||(col==1 && col>6))     
                    System.out.print("* ");
                    else
                        System.out.print("  ");}
                      System.out.println();

    }}

    private static void pattern_n() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
    if(  col == 5 ||line==9 || col+line==6)
                System.out.print("* ");
            else 

                    System.out.print("  ");}
    System.out.println();

    }}

    private static void patternN() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
    if(  col == 1 ||col==9  || line==col)
                System.out.print("* ");
            else 

                    System.out.print("  ");}
    System.out.println();

    }}

    private static void patternH() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
    if(  col == 1 ||col==9 ||line==5 )
                System.out.print("* ");
            else 

                    System.out.print("  ");}
    System.out.println();

    }}
    private static void pattern1() {
        // TODO Auto-generated method stub
        for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
            {
    if( line==1 || line==9 || col == 1 ||col==9 ||line==col |line+col==10)
                System.out.print("* ");
            else 

                    System.out.print("  ");}
    System.out.println();
                }}}

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs