Click here to Skip to main content
15,885,824 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want to print the star in box format
****
*  *
*  *
****



what i need to do

C#
for (int i = 0; i < 3; i++)
           {
               for (int j = 0; j <= i; j++)
               Console.Write("*");
               Console.WriteLine();

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 10-Aug-14 23:51pm
v2

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

But...this is almost trivial:

1) Print the top line.
2) Loop for the middle lines
2.1) Print the left edge
2.2) Loop for the blanks - print them all
2.3) Print the right edge, and a new line
3) Print the bottom line.

Me, I'd make two methods: PrintRowOfStars to do the top and bottom, and PrintBoxRow to do the centres. Both methods would take a parameter - the length of the line - and print that many characters and a newline.
 
Share this answer
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace starbox
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 1; i++)
            {
                for (int j = 0; j <= 3; j++) //to print the first line
                    Console.Write("*");
                Console.WriteLine(""); //to go to second line
            }
           for (int i = 0; i <=1; i++) //to repeat for two times 
            {

                for (int j = 0; j<=0; j++)
              // Console.WriteLine("");
                    Console.Write("*"); // to print in second row and first column
               for (int j=1;j<=2;j++)
                   Console.Write(" "); // to bring two spaces for next *
               for (int j = 3; j <= 3; j++)
                   Console.Write("*"); // to print star in second row and last column
               Console.WriteLine();      
            }
                for (int i = 3; i < 4; i++)
                {

                    for (int j = 0; j <= 3; j++)

                      Console.Write("*");
                    //Console.WriteLine("");
                }
                Console.ReadKey();
            }
        }
    }
 
Share this answer
 
Comments
[no name] 11-Aug-14 7:17am    
Since you do homework for people do you take tests for them as well?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900