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)