DEV Community

hema latha
hema latha

Posted on

Nested for loop

package Forloopbase;

public class Forloop {

public static void main(String[] args) {
    //pattern();
    pattern1();
    // TODO Auto-generated method stub
Enter fullscreen mode Exit fullscreen mode

}
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();
            }}

private static void pattern() {
    // TODO Auto-generated method stub
     for(int line = 1; line<=9; line++)
        {
            for(int col=1; col<=9; col++)
                {System.out.print(" * ");}
            System.out.println();
        }}}
Enter fullscreen mode Exit fullscreen mode

out put

Image description

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