0

I need help, please explain :(

var n = 6; for (int i=1;i<=n;i++) { for (int a=1;a<=n;a++) { if ((i != 1) && (i != n) && (a != 1) &&(a != n)) { Console.Write(“ “); } else { Console.Write(“*”); } } Console.WriteLine(); }

14th Jan 2018, 6:07 PM
Galin Georgiev
Galin Georgiev - avatar
3 Respuestas
+ 2
It prints a box, 6 by 6. If i = 1 or 6, or a = 1 or 6. It is the border of the box and it prints a '*'. If a and i are not 1 or 6 it is inside the box and it prints a ' '.
14th Jan 2018, 6:30 PM
Paul
Paul - avatar
0
If you change it do this and work with characters instead of strings it works. var n = 6; for (int i=1;i<=n;i++) { for (int a=1;a<=n;a++) { if ((i != 1) && (i != n) && (a != 1) &&(a != n)) { Console.Write(' '); } else { Console.Write('*'); } } Console.WriteLine(); }
14th Jan 2018, 6:26 PM
Jente
0
oh .... now i get it 😁😁 thank you so much i could not figure it out i just couldn’t explain my self what is each step of the loop doing to get them empty spaces ok ok 😁😁 thanks !!
14th Jan 2018, 7:08 PM
Galin Georgiev
Galin Georgiev - avatar