English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am trying to do a brainteaser using C# code. It sould end up looking like this:
*
**
***
****
*****
******
*******
********
*********
its not working (giving me something different please help?



namespace BrainTeaser
{

class HalfDiamond
{

static void Main()
{

for (int i =1; i < 10; i++)
{

for (int j = 0; j < 10; j++)
Console.WriteLine("*");
Console.WriteLine();

}


}


}


}

2007-01-16 14:24:24 · 4 answers · asked by Sad Mom 3 in Computers & Internet Programming & Design

4 answers

string x;

for(int i = 1; i < 10; i++) {
x = "";
for(int y = 0; y < i; y++) {
x += "*";
}
Console.WriteLine(x);
}

2007-01-16 15:16:00 · answer #1 · answered by Anonymous · 0 0

change the "j < 10" to be "j < i" and change the line Console.WriteLine("*"); to be Console.Write("*"); so you dont get a Enter key happening after each "*" displayed to make the one line...The following writeline will take care of that for each row..

2007-01-16 14:41:12 · answer #2 · answered by Anonymous · 1 1

To output better use:

Console.WriteLine("".PadLeft(i, '*'));

This will eliminate your entire looking structure with a single line.

2007-01-18 05:36:33 · answer #3 · answered by Amil 1 · 0 0

Consider yourself REPORTED. CHEATER!

2007-01-16 16:29:42 · answer #4 · answered by twobearcatz 1 · 0 2

fedest.com, questions and answers