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 %26lt; 10; i++)
{
for (int j = 0; j %26lt; 10; j++)
Console.WriteLine("*");
Console.WriteLine();
}
}
}
}
C# code help?
string x;
for(int i = 1; i %26lt; 10; i++) {
x = "";
for(int y = 0; y %26lt; i; y++) {
x += "*";
}
Console.WriteLine(x);
}
Reply:Consider yourself REPORTED. CHEATER!
Reply:change the "j %26lt; 10" to be "j %26lt; 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..
Reply:To output better use:
Console.WriteLine("".PadLeft(i, '*'));
This will eliminate your entire looking structure with a single line.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment