0
Square
how to bring out such a figure? * * * * * * * * * * https://code.sololearn.com/cGk5OAjyA3Z4/?ref=app
12 Answers
+ 2
Try it in same way as you did it for x. Try it and post your attempt,if you find difficulty...
edit: Best of Sport
if this code not your implementation then observe it 'where spaces adding and where printing * '. you will get similar examples here only.. so try it and find some logic, if that does not work then use this thread for help.. some one definitely help. happy learning...
+ 1
Compare when j==0 and j==n-1 print * else space
+ 1
Best of Sport No, not like that
public class Program
{
public static void main(String[] args) {
int n=7;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if((j==(1) || (j==n-1)))
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
//This is your expected code?
+ 1
visph why you are making it complicated
if I==1 || j==1 || j==n || I==n
Print*
Else space
0
Pariket you copied the same answer as that of mine 😅
0
Best of Sport your code print single character but you need to repeat it for some cycles so you have use a loop. You have some solutions already by other posted. I just want to add a change in @visph code that use i<n-1 condition in 1st and last for loop...
as
for (int i=0; i<n-1; ++i)
System.out.print("*");
0
Jayakrishna🇮🇳 if you want to replace n by n-1 in first and last loop conditions, you should also replace < by <= ;P
0
No visph . I mean to shape it by cut edge in 1st and last line to shape D. A more suitable than a rectangle ◻. See output difference.
0
Oh. I was thinking about shape in description. (The D pattern).Not about squire.
so I was wrong ..
visph. So no need any change
0
well, I was focused on the question title ^^
to get the exact shape given by OP in description, assuming n would be the number of lines:
https://code.sololearn.com/ccNJpso4VWV6/?ref=app