c# - Starpattern in console app -


i need create following pattern: http://puu.sh/dx3fn/500f5ee468.png

it homework, question failed first time. read should have used "*" 1 time, how work in case? appreciate if give me insight in how think.

my code down below:

using system; class starpattern {     public static void main()     {         (int = 0; < 5; i++)         {             console.write("*");         }         (int = 0; <= 0; a++)         {             console.writeline("");             console.write("*");         }         (int c = 0; c <= 0; c++)         {             console.writeline("   *");         }         (int d = 0; d <= 1; d++ )         {             console.write("*");             console.writeline("   *");         }         (int e = 0; e < 5; e++ )         {             console.write("*");         }         console.readline();     }                  } 

you can simplify code nesting loops outer (i) = rows , inner (j) = columns. looking @ sample, want write out if you're on boundary of either can add condition write out on min , max.

private static void main(string[] args) {     (int = 0; <= 4; i++)     {         (int j = 0; j <= 4; j++)         {             if (i == 0 || == 4 || j == 0 || j == 4)             {                 console.write("*");             }             else             {                 console.write(" ");             }         }         console.writeline();     }     console.readkey(); } 

i'd replace 0 constant called min , 4 constant called max save duplicating them. way, increase size of square changing constants.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -