package Forloopbase;
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();
}}}
out put
*
* *
* *
- *
- *
- * * * * * * * * *
- *
*
*
*
- * * * * * * * * *
*
*
*
*
*
*
- *
- *
- *
- *
- * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * *
- *
- *
- * * * * * * * * * *
*
*
*
*
*
*
*
*
- *
- *
- * * * * * * * * * *
- *
- *
- * * * * * * * * * *
- *
- *
- * * * * * * * * * * * * * *
Top comments (0)