C # An example of Bigbird. I changed myself.

Source: Internet
Author: User

Using System;

Using System. Collections. Generic;

Using System. Text;

 

Namespace PrintNumbers

{

/// <Summary>

/// Draw a loose.

/// </Summary>

///

Public class DrawTree

{

Int Width;

 

Public int Width1

{

Get {return Width ;}

Set {Width = value ;}

}

Int Height;

 

Public int Height1

{

Get {return Height ;}

Set {Height = value ;}

}

Int x, y;

Public DrawTree ()

{

Console. WriteLine ("draw a loose number to show you how powerful I am. ");

}

 

Public void EnterWidth ()

{

 

Do

{

Int temp = 0;

 

Console. Write ("Enter the width of pine tree :");

If (! Int. TryParse (Console. ReadLine (), out temp ))

{

Console. WriteLine ("enter a number! (ODD )");

Continue;

}

Else if (temp % 2 = 0)

{

Console. WriteLine ("enter an odd number! ");

Continue;

}

Else

{

Width = temp;

Break;

}

 

 

} While (true );

}

 

Public void EnterHeight ()

{

Int temp = 0;

 

Do

{

 

Console. Write ("Enter the height of the pine tree :");

If (! Int. TryParse (Console. ReadLine (), out temp ))

{

Console. WriteLine ("enter a number! ");

Continue;

}

Else

{

Height = temp;

Break;

}

 

 

 

} While (true );

}

Public override string ToString ()

{

Return string. format ("\ n = =============\ nNow! Open your dog's eye and see if I will draw a tree for you! \ N tree Height is {0,-6} the Height is {1,-5} ", Width, Height );

}

Public void DrawATree ()

{

This. DrawATree (Width, Height );

}

Public void DrawATree (int width, int height)

{

/// <Summary>

/// Create a canopy

/// </Summary>

///

// For (int I = 0; I <length; I ++)

//{

//}

For (int I = 1; I <width; I ++)

{

For (int k = 0; k <width-I; k ++)

{

Console. Write ("");

 

}

For (int j = 0; j <2 * I-1; j ++)

{

Console. Write ("*");

}

Console. WriteLine ();

}

For (int m = 0; m

{

For (int I = 0; I <width-1; I ++)

{

Console. Write ("");

}

Console. WriteLine ("* \ n ");

}

 

}

 

 

 

 

 

 

}

 

Class Program

{

Static void Main (string [] args)

{

DrawTree tree = new DrawTree ();

Tree. EnterWidth ();

Tree. EnterHeight ();

Console. WriteLine (tree. ToString ());

Tree. DrawATree ();

}

}

}

 

// Draw a pine tree to show you my strength.

Enter the width of pine tree: 12

Enter an odd number!

Enter the width of pine tree: 12

Enter an odd number!

Enter the width of pine tree: 15

Enter the height of pine tree: 12

 

 

 

 

========================================================

Now! Open your dog's eye and see if I will draw a tree for you!

Tree Height: 15; 12

*

***

*****

*******

*********

***********

*************

***************

*****************

*******************

*********************

***********************

*************************

***************************

*

 

*

 

*

 

*

 

*

 

*

 

*

 

*

 

*

 

*

 

*

 

*

 

Press any key to continue...

// Sorry. The console is OK. It is estimated that the spaces are different.

 

//// In another example, find the odd number.

Using System;

Using System. Collections. Generic;

Using System. Text;

 

Namespace Sum

{

/// <Summary>

/// This example is the reference answer to the first assignment question in the second chapter.

/// Calculate the sum of 1-odd numbers

/// </Summary>

Class Number

{

Int x;

Int y;

Int temp;

Public Number ()

{

Console. WriteLine ("finding all odd numbers between two numbers ");

 

}

/// <Summary>

/// Enter the first number

/// </Summary>

///

Public void EnterFirstNumber ()

{

Console. WriteLine ("Enter the first number ");

While (true)

{

If (int. TryParse (Console. ReadLine (), out temp ))

{

X = temp;

Break;

}

Else

{

Console. WriteLine ("enter the correct number ");

Continue;

}

}

}

/// <Summary>

/// Enter the second number

/// </Summary>

///

 

Public void SecondNumber ()

{

Console. WriteLine ("enter the second number ");

While (true)

{

If (int. TryParse (Console. ReadLine (), out temp ))

{

If (temp! = X)

{

Y = temp;

Break;

}

Else

{

Console. WriteLine ("two numbers cannot be the same ");

Continue;

}

}

Else

{

Console. WriteLine ("enter the correct number ");

Continue;

}

}

}

/// <Summary>

/// Find the odd number!

/// </Summary>

///

Public void Find odd ()

{

Int temp;

If (x> y)

{

Temp = y;

Y = x;

X = temp;

}

For (; x <= y; x ++)

{

If (x % 2! = 0)

{

Continue;

}

Console. Write ("{0,-5}", x );

}

}

 

 

}

Class Program

{

Static void Main (string [] args)

{

Number number = new Number ();

Number. EnterFirstNumber ();

Number. SecondNumber ();

Number. Find odd ();

 

}

}

}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.