Data Type (2)

Source: Internet
Author: User

Tag: blog HTTP Io OS AR for SP data 2014

Double D = double. parse (console. Readline ());
D = math. Pi; // circumference Rate
D = math. SQRT (d); // kaifang
D = math. Ceiling (d); // This is an integer. When the decimal point is greater than 0, the upper limit is added to the integer and the integer is added to the integer.
D = math. Floor (d); // remove all digits after the decimal point, and take the integer without carrying
D = math. Round (d); // rounding. If the integer part is an odd number, the value is. 5. If the integer part is an even number, the value is. 5.


String S = console. Readline ();
Datetime dt = new datetime (); // The default initialization time is January 1, 0001 12:00:00 AM.
Dt = datetime. Now; // obtain the local time on the computer
Int I = DT. Year; // extract year
Dayofweek d = DT. dayofweek; // obtain the day of the week represented by this instance
Int I = DT. dayofyear; // obtain the day of the current year. Only the int type value is returned.
Dt = datetime. parse (s );
S = DT. tostring ("yyyy-mm-dd"); // converts the date and time type to the string type. // yyyy, mm, DD, is a bitwise character.
System. timespan time = new timespan (); // the timespan Time Interval Type indicates a time interval, which can be added to a maximum of days.
Dt = DT. Add (time); // The parameter is a value of the timespan type.
Dt = DT. adddays (); // The number of days to add. The parameter is double.
Dt = DT. addhours (); // The number of hours to add. The parameter is double.
Dt = DT. addmonths (); // number of months to be added. The parameter is int and the current face is 31 days. When the number of days exceeds the limit, the maximum value is obtained and the next month is not entered.
Dt = DT. addyears (); // Add multiple teenagers. The parameter is int. When the 29 th day of the leap year is used up, the 28 day is not displayed for the leap year, And the next month is not entered.

Exercise:

 

Exercise 2:

// Judge whether the input is correct
Console. Write ("Enter the year :");
Int Nian = convert. toint32 (console. Readline ());
Console. Write ("Enter the month :");
Int Yue = convert. toint32 (console. Readline ());
Console. Write ("Enter the day :");
Int rI = convert. toint32 (console. Readline ());

If (Nian> = 0 & Nian <= 9999)
{
Console. Write ("year input is correct! ");
}
Else
{
Console. Write ("year input error! ");
}

If (Yue> = 1 & Yue <= 12)
{
Console. Write ("the monthly input is correct! ");
}
Else
{
Console. Write ("Monthly input error! ");
}

If (RI> = 1 & RI <= 31 & (Yue = 1 | Yue = 3 | Yue = 5 | Yue = 7 | Yue = 8 | Yue = 10 | Yue = 12 ))
{
Console. Write ("the input date is correct! ");
}
Else if (RI> = 1 & RI <= 30 & (Yue = 4 | Yue = 6 | Yue = 9 | Yue = 11 ))
{
Console. Write ("the input date is correct! ");
}
Else if (RI> = 1 & RI <= 29 & Nian % 100 = 0 & Nian % 400 = 0 & Yue = 2)
{
Console. Write ("the input date is correct! ");
}
Else if (RI> = 1 & RI <= 29 & Nian % 4 = 0 & Nian % 100! = 0 & Nian % 400! = 0 & Yue = 2)
{
Console. Write ("the input date is correct! ");
}
Else if (RI> = 1 & RI <= 28 & Yue = 2)
{
Console. Write ("the input date is correct! ");
}
Else
Console. Write ("daily input error! ");
Console. Readline ();

Result

Method 2:

Datetime dt1 = new datetime ();
Datetime dt2 = new datetime ();
Int I = 0;
Int sum = 0;
Try
{
Dt1 = datetime. parse (console. Readline ());
Dt2 = datetime. parse (console. Readline ());
}
Catch (exception E)
{
Console. Write ("input error! ");
I ++;
}
Finally
{
If (I = 0)
{
If (dt1> dt2)
{
Datetime dt3 = dt2;
Dt2 = dt1;
Dt1 = dt3;
}
For (int K = dt1.year; k <dt2.year; k ++)
{
If (K % 100 = 0)
{
If (K % 400 = 0)
{
Console. Write (K + "");
Sum ++ = 366;
}
Else
{
Console. Write (K + "not a leap year ");
Sum ++ = 365;
}
}
}

}
}
}


Sum + = dt2.dayofyear-dt1.dayofyear;
Console. writeline ("difference" + sum + "day ");
Console. Readline ();

 

Exercise 3:

// Generate a four-digit Verification Code randomly and enter the correct verification code.
String S = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 ";
Random r = new random ();
Int YI = R. Next (63 );
Int ER = R. Next (63 );
Int San = R. Next (63 );
Int Si = R. Next (63 );

String A = S. substring (Yi, 1 );
String B = S. substring (ER, 1 );
String c = S. substring (San, 1 );
String d = S. substring (Si, 1 );

String suiji = A + B + C + D;
Console. writeline (suiji );

Console. Write ("Enter :");

While (true)
{
String shuru = console. Readline ();
Shuru = shuru. toupper ();
Suiji = suiji. toupper ();
If (shuru = suiji)
{
Console. Write ("the input is correct! ");
Break;
}
Else
{
Console. Write ("Enter it again! ");
}
}
Console. Readline ();

 

Exercise 4:

 

Data Type (2)

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.