private static void pattern1() {
for(int row=1;row<=9;row++)
{
for(int col=1;col<=9;col++) {
if(col==5 || row==9 ||col+row==6 ) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
.........................................................................
OUTPUT:
*
* *
* *
* *
* *
*
*
*
* * * * * * * * *
Enter fullscreen mode
Exit fullscreen mode
private static void pattern2() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(row==1|| col==9&&row<=5||row==5||row==9||col==1&&row>=5) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * * * *
*
*
*
* * * * * * * * *
*
*
*
* * * * * * * * *
Enter fullscreen mode
Exit fullscreen mode
private static void pattern3() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(row==1|| row==9|| col==9|| row==5) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * * * *
*
*
*
* * * * * * * * *
*
*
*
* * * * * * * * *
Enter fullscreen mode
Exit fullscreen mode
private static void pattern4() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(col==1&&row<=6|| row==6|| col==5&&row>=3) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
*
*
* *
* *
* *
* * * * * * * * *
*
*
*
Enter fullscreen mode
Exit fullscreen mode
private static void pattern5() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(row==1|| row==9|| row==5|| col==1&&row<=5|| col==9&&row>=5) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * * * *
*
*
*
* * * * * * * * *
*
*
*
* * * * * * * * *
Enter fullscreen mode
Exit fullscreen mode
private static void pattern6() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(row==1|| row==9|| col==1|| row==5 || col==9&&row>=5) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
.........................................................................
OUTPUT:
* * * * * * * * *
*
*
*
* * * * * * * * *
* *
* *
* *
* * * * * * * * *
Enter fullscreen mode
Exit fullscreen mode
private static void pattern7() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(col==8|| row==1&&col<=8) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * * *
*
*
*
*
*
*
*
*
Enter fullscreen mode
Exit fullscreen mode
private static void pattern8() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(row==1|| row==9|| col==1|| row==5 || col==9) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * * * *
* *
* *
* *
* * * * * * * * *
* *
* *
* *
* * * * * * * * *
Enter fullscreen mode
Exit fullscreen mode
private static void pattern9() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(row==1|| col==9|| row==5|| col==1&&row<=5) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * * * *
* *
* *
* *
* * * * * * * * *
*
*
*
*
Enter fullscreen mode
Exit fullscreen mode
private static void pattern10() {
for(int row=1;row<=9;row++) {
for(int col=1;col<=9;col++) {
if(col==1||col==4|| col==9|| row==1&&col>=4|| row==9&&col>=4) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
.........................................................................
OUTPUT:
* * * * * * *
* * *
* * *
* * *
* * *
* * *
* * *
* * *
* * * * * * *
Enter fullscreen mode
Exit fullscreen mode
Top comments (0)