*********
* *
* *
* *
* * *
* *
* *
* *
*********
Solution:-
class square
{
public static void main(String abc[])
{
int size=9; //You can change the value of size variable to minimize or maximize square
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(i>=1&&i<=size-2&&j>=1&&j<=size-2)
{
if(i==size/2&&j==size/2)
{
System.out.print("*");
}
else{
System.out.print(" ");
}
}
else
{
System.out.print("*");
}
}
System.out.println();
}
}
}
* *
* *
* *
* * *
* *
* *
* *
*********
Solution:-
class square
{
public static void main(String abc[])
{
int size=9; //You can change the value of size variable to minimize or maximize square
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(i>=1&&i<=size-2&&j>=1&&j<=size-2)
{
if(i==size/2&&j==size/2)
{
System.out.print("*");
}
else{
System.out.print(" ");
}
}
else
{
System.out.print("*");
}
}
System.out.println();
}
}
}
No comments:
Post a Comment