0% found this document useful (0 votes)
30 views

Write A Java Program Using Switch Case To Print Any 10 Patterns

The document describes a Java program that uses a switch case statement to print 10 different patterns. The program contains a switch case with 10 cases that each contain nested for loops to print a different pattern by varying the number of spaces and asterisks printed on each line.

Uploaded by

Sandeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Write A Java Program Using Switch Case To Print Any 10 Patterns

The document describes a Java program that uses a switch case statement to print 10 different patterns. The program contains a switch case with 10 cases that each contain nested for loops to print a different pattern by varying the number of spaces and asterisks printed on each line.

Uploaded by

Sandeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Write a java program using switch case to print any 10

patterns.

public class Patterns


{
public static void main(String args[])
{
int i,j,k;
switch(k)
{
case 1:
for(i=1; i<=5; i++)
for(j=4; j>=i; j--)
{
System.out.print(" ");
}
for(k=1; k<=(2*i-1); k++)
{
System.out.print("*");
}

System.out.println("");
break;
case2:
for(i=5;i>=1;i--)
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
System.out.print("*");
}
System.out.println();
break;
case3:
for(i=5;i=1;i--)
for(j=1;j=i;j++)
{
System.out.print(" ");

}
for(k=5;k>=i;k--)
{
System.out.print("*");
}
System.out.println();
break;
case4:
for(i=5;i>=1;i--)
for(j=5;j>i;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print("*");
}
System.out.println();
break;

case5:
for(i=1;i<=5;i++)
for(j=i;j<5;j++)
{
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
System.out.print("*");
}
System.out.println();
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
System.out.print(" ");
}
for(k=1;k<(i*2);k++)
{
System.out.print("*");

}
System.out.println();
break;
case6:
for(i=0; i<5; i++)
k=1;
for(j=0; j<=i; j++)
{
System.out.print(k+ " ");
k++;
}
System.out.println();
break;
case7:
for(i=0; i<5; i++)
for(j=0; j<=i; j++)
{
System.out.print(k+ " ");
k++;

}
System.out.println();
break;
case8:
for(int i=0;i<5;i++)
for(int j=0;j<5-i;j++)
{
System.out.print(" ");
}
for(int k=0;k<=i;k++)
{
System.out.print("$ ");
}
System.out.println();
break;
case9:
for(int i=5;i>0;i--)
for(j=0;j<i;j++)
{

System.out.print(" ");
}
for (int k=j;k<5;k++)
{
System.out.print(" $ ");
}
System.out.println("");
case10:
for(int i=0;i<level;i++)
for(int j=0;j<level-i-1;j++)
{
System.out.print(" ");
}
for(int k=level-i;k<=level;k++)
{
System.out.print("*");
}
for(int k=level-i;k<level;k++)
{

System.out.print("*");
}
for(int j=0;j<level-i;j++)
{
System.out.print(" ");
}

System.out.print("\n");
break;
default1:
System.out.println("Not Possible");
}
}
}

You might also like