0914 exercises, class type (user-defined type)

Source: Internet
Author: User

One, enter your ID number, identify the year of the month and the day of birth, and calculate your age

Console.Write ("Please enter your ID number:"); Output a string of characters "Please enter your ID number"

string s = Console.ReadLine (); Define the ID of this string of characters in s This variable is waiting for you to enter (input)

string n = s.substring (6,4); Defines n equals s 4 digits from the beginning of the 6th digit

String y = s.substring (10,2); Defines y equals s 2 digits from the beginning of the 10th digit

String r = S.substring (12, 2); Defines y equals s 2 digits from the beginning of the 12th digit

Console.WriteLine ("Your date of birth is {0} years {1} months {2} days", n,y,r); Output "What year is your date of birth and January?"

int shu = Int.  Parse (n); converts n to int type Shu

int j = 2015; Define J equals 2015

int Sui=j-shu; Define Sui equals 2015-n

Console.WriteLine ("You are {0} years old this year", Sui); Output How old are you this year?

Second, produce a random number, show the random winning number

Random r = new Random ();
for (int i = 0; I <=; i++)
{
int shu = r.next (1001, 9999);
Console.WriteLine (SHU);
Thread.Sleep (100); Delay, per millisecond
Console.clear ();
}
Console.WriteLine ("Winning number is: 1002");

Third, crawl error

int CuO = 0; Define a variable
Console.WriteLine ("Please enter the date time"); Output a text "Please enter a time date"
string s = Console.ReadLine ();
Try
{
DateTime dt = DateTime.Parse (s); Convert a string type to a time date type
}
catch (Exception ex)//Capture Error
{
Console.WriteLine ("Error");
Cuo=1; If the variable CuO =1, that's the mistake.
}
if (cuo==0)//if variable CuO = 0 That's right
{
Console.WriteLine ("Correct");
}

Four, split

string s = "A|b|c|ab|cd|c|d";

string[] str = s.split (' | ');

foreach (string d in str)

//{

Console.WriteLine (d);

//}

string s = "A|b|c|ab|cd|c|d";

string[] str = s.split (' | ');

Console.WriteLine (Str[0]);

Console.WriteLine (Str[1]);

Console.WriteLine (Str[2]);

Console.WriteLine (Str[3]);

Console.WriteLine (Str[4]);

Console.WriteLine (Str[5]);

Console.WriteLine (Str[6]);

Five

//Math: There are some methods for handling numbers, static methods
           //int i = Math.Abs (-5); Take absolute value
           //console.writeline (i);
           //double A = math.ceiling (1.1); Ceiling
           //console.writeline (a);
           //math.floor (1.9); Lower Limit
           //console.writeline (MATH.PI);//PI
           //console.writeline (Math.Round (1.41));// Rounding
           //console.writeline (Math.pow (2,3)); /Mu-fang
           //console.writeline (math.sqrt (25)); /square root

0914 exercises, class type (user-defined type)

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.