C # input and output, type, operator, statement exercises

Source: Internet
Author: User

Please enter your name, age, work unit,
Stitched into a complete sentence
My name is * * *, this year * * years old, work in * * *.
Console.Write ("Please enter your name:");
String name = Console.ReadLine ();
Console.Write ("Please enter your Age:");
String age = Console.ReadLine ();
Console.Write ("Please enter your work unit:");
String Danwei = Console.ReadLine ();
Console.WriteLine ("Your name is" + name + ", the Age is" + Ages + "and the work unit is" + Danwei + ".) ");
Console.WriteLine ("Your name is {0}, the age is {1}, the work unit is {2}."} ", name, age, Danwei);


Excuse me, what time is it now?
Only answer hours 0~23
If morning AM
If the afternoon pm-12 the timekeeping
Console.Write ("Excuse me, what time is it?") ");
int time = Int. Parse (Console.ReadLine ());
if (time >= 0 && time <= 23)
{
String t = time > 12? (Time-=) + "PM": Time + "AM";
Console.WriteLine ("The time you entered is:" + t);
}
Else
{
Console.WriteLine ("You entered the wrong time");
}


//Blind Date process!!
//Q: Do you have a house? "Get Married"
//No "Are you rich?" "Have" to buy a house before marriage "
//No" then you have the ability? "Have" first make money, then buy a house, then marry "
//No" Baibai!!!!!!! "
Console.Write (" Do you have a house? ");
String x = Console.ReadLine ();
if (x = = "has")
{
Console.WriteLine ("You're married! ");
}
Else if (x = = "No")
{
Console.Write ("Are you rich?") ");
String y = Console.ReadLine ();
if (y = = "has")
{
Console.WriteLine ("Then you go to buy a house and then you get married!") ");
}
Else if (y = = "no")
{
Console.Write ("Do you have the ability to make money?") ");
String z = Console.ReadLine ();
if (z = = "has")
{
Console.WriteLine ("Then you try to make money, buy a house and get married!") ");
}
Else if (z = = "No")
{
Console.WriteLine ("You have no power, no money, no house, what do you do with a blind date?") Bye! ");
}
Else
{
Console.WriteLine ("You can't even answer my questions, I can't see your sincerity, bye! ");
}
}
Else
{
Console.WriteLine ("Please answer my question");
}
}
Else
{
Console.WriteLine ("Please answer my question");
}


There is a set of functions: y = x (x<1);
y = 2x-1 (1<=x<10);
y = 3x-11 (x>=10).
Inside the parentheses is the condition of the X.
Implement the function, arbitrarily enter an x value, output y value.
Console.Write ("Please enter a number:");
Double x = Double. Parse (Console.ReadLine ());
if (x < 1)
{
Double y = x;
Console.WriteLine (y);
}
else if (x < 10)
{
Double y = 2 * x-1;
Console.WriteLine (y);
}
Else
{
Double y = 3 * x-11;
Console.WriteLine (y);
}


Enter integers A and B,
If A2+B2 is greater than 100, the result of the output a2+b2
Otherwise the sum of two outputs
Console.Write ("Please enter an integer a:");
int a = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter an integer b:");
int b = Int. Parse (Console.ReadLine ());
if (A * 2 + b * 2 > 100)
{
Console.WriteLine ("Result:" + (A * 2 + b * 2));
}
Else
{
Console.WriteLine ("Result:" + (A + b));
}


Enter a year to determine whether it is leap years
(a leap year is divisible by 400 for years that can be divisible by 4 but not divisible by 100)
Console.Write ("Please enter a year:");
int year = Int. Parse (Console.ReadLine ());
if (year >= 0 && year <= 9999)
{
if (year% 4 = = 0 && year%!! = 0 | | year% 400 = = 0)
{
Console.WriteLine ("The Year you entered is a leap years");
}
Else
{
Console.WriteLine ("The year you entered is not a leap years");
}
}
Else
{
Console.WriteLine ("You entered the wrong year");
}


Equation ax2+bx+c=0; one-dimensional two-time equation, root-finding
=B2-4AC; If the <0 equation is not real roots
If >0, the equation has two different real roots X1 x2
If =0, the equation has two identical real roots
Root Formula X1= (-B+MATH.SQRT ())/a*2
X2= (-B-MATH.SQRT ())/a*2
Console.WriteLine ("The root of the equation ax^2+bx+c=0");
Console.Write ("Please enter a value:");
Double A = double. Parse (Console.ReadLine ());
Console.Write ("Please enter the value of B:");
Double b = Double. Parse (Console.ReadLine ());
Console.Write ("Please enter the value of C:");
Double c = Double. Parse (Console.ReadLine ());
if (A! = 0)
{
Double de = b * b-4 * a * C;
if (De < 0)
{
Console.WriteLine ("One-yuan two-time equation has no real roots. ");
}
else if (de = = 0)
{
Double X1 = (-B + math.sqrt (DE))/(A * 2);
Double x2 = (-B + math.sqrt (DE))/(A * 2);
Console.WriteLine ("One-yuan two-time equation has two identical real roots: x1=x1=" + x1);
}
Else
{
Double X1 = (-B + math.sqrt (DE))/(A * 2);
Double x2 = (-b-math.sqrt (DE))/(A * 2);
Console.WriteLine ("Unary two-time equations have two different real roots: x1={0},x2={1}. ", X1, x2);
}
}
Else
{
Console.WriteLine ("A=0, the equation is not a unary two-time equation. ");
}

Standard Weight:
Men's weight = height -100±3
Height-weight-100 =±3
Lady weight = height -110±3
Console.Write ("Excuse me, are you a boy or a girl?") ");
string x = Console.ReadLine ();
if (x = = "Boy")
{
Console.Write ("Please enter your height (cm):");
Double s = Double. Parse (Console.ReadLine ());
Console.Write ("Please enter your weight (kg):");
Double T = Double. Parse (Console.ReadLine ());
if (T > s-100-3 && T < s-100 + 3)
{
Console.WriteLine ("Your body is very standard, please keep it!") ");
}
else if (T < s-100-3)
{
Console.WriteLine ("Your weight is low, oh");
}
Else
{
Console.WriteLine ("Your weight is high oh");
}
}
else if (x = = "Schoolgirl")
{
Console.Write ("Please enter your height (cm):");
Double s = Double. Parse (Console.ReadLine ());
Console.Write ("Please enter your weight (kg):");
Double T = Double. Parse (Console.ReadLine ());
if (T > s-110-3 && T < s-110 + 3)
{
Console.WriteLine ("Your body is very standard, please keep it!") ");
}
else if (T < s-110-3)
{
Console.WriteLine ("Your weight is low, oh");
}
Else
{
Console.WriteLine ("Your weight is high oh");
}
}
Else
{
Console.WriteLine ("The gender you entered is wrong. ");
}


Please enter the year, month, and day separately
Determine if the format is correct
Console.Write ("Please enter the Year:");
int year = Int. Parse (Console.ReadLine ());
if (year >= 0 && year <= 9999)
{
Console.Write ("Please enter the month:");
int month = Int. Parse (Console.ReadLine ());
if (Month > 0 && month <= 12)
{
Console.Write ("Please enter Date:");
int day = Int. Parse (Console.ReadLine ());
if (Day > 0 && Day <= 31)
{
if (month = = 1 | | month = = 3 | | month = = 5 | | month = = 7 | | month = 8 | | month = = | | month = = 12)
{
Console.WriteLine ("The date you entered is: {0} years, {1} months, {2} days. ", year, month, day);
}
else if (month = = 4 | | month = = 6 | | month = = 9 | | month = = 11)
{
if (day = = 31)
{
Console.WriteLine ("You entered the wrong date!") ");
}
Else
{
Console.WriteLine ("You entered the date is:" + year + "years," + Month + "month," + Day + "days.) ");
}
}
Else
{
if (Day <= 28)
{
Console.WriteLine ("The date you entered is: {0} years, {1} months, {2} days. ", year, month, day);
}
else if (day = = 29)
{
if (year% 4 = = 0 && year%!! = 0 | | year% 400 = = 0)
{
Console.WriteLine ("You entered the date is:" + year + "years," + Month + "month," + Day + "days.) ");
}
Else
{
Console.WriteLine ("You entered the wrong date!");
}
}
Else
{
Console.WriteLine ("You entered the wrong date!") ");
}
}
}
Else
{
Console.WriteLine ("You entered the wrong date!") ");
}
}
Else
{
Console.WriteLine ("The Month you entered is incorrect!) ");
}
}
Else
{
Console.WriteLine ("You entered the wrong year!") ");
}


Enter month, enter date number
February defaults to 28 days
The output is the first day of the year
int m1 = to, M2 =, M3 = To, M4 =, M5 = To, M6 =, M7 = to, M8 = to, M9 = 31, M10 =, M11 =: M12
Console.Write ("Please enter the month:");
int m = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter the date:");
int d = Int. Parse (Console.ReadLine ());
Switch (m)//() The name of the variable you want to view--m can be a string or a number
{//Each case followed by a value that might be a value
Case 1://1 If the string is quoted
Console.WriteLine ("Today is this year's first" + d.tostring () + "Day! ");
Break
Case 2:
Console.WriteLine ("Today is the first of the Year" + (M1 + D). ToString () + "Day!" ");
Break
Case 3:
Console.WriteLine ("Today is the first of the Year" + (M1 + m2 + d). ToString () + "Day!" ");
Break
Case 4:
Console.WriteLine ("Today is the first of the Year" + (M1 + m2 + m3 + d). ToString () + "Day!" ");
Break
Case 5:
Console.WriteLine ("Today is the first of the Year" + (M1 + m2 + m3 + m4 + D). ToString () + "Day!" ");
Break
Case 6:
Console.WriteLine ("Today is the first of the Year" + (M1 + m2 + m3 + M4 + M5 + D). ToString () + "Day!" ");
Break
Case 7:
Console.WriteLine ("Today is the first of the Year" + (M1 + m2 + m3 + M4 + M5 + M6 + D). ToString () + "Day!" ");
Break
Case 8:
Console.WriteLine ("Today is the first of the Year" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + D). ToString () + "Day!" ");
Break
Case 9:
Console.WriteLine ("Today is this year's first" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + D). ToString () + "Day!" ");
Break
Case 10:
Console.WriteLine ("Today is this year's first" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + D). ToString () + "Day!" ");
Break
Case 11:
Console.WriteLine ("Today is this year's first" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + D). ToString () + "Day!" ");
Break
Case 12:
Console.WriteLine ("Today is this year's first" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + M11 + D). ToString () + "Day!" ");
Break
Default
Console.WriteLine ("You entered the wrong!") ");
Break
}


Please enter an integer within 100 to determine if it is related to seven
Multiples of 1.7 a%7==0
2. Single digit is 7 a%10==7
3.10-digit is 7 a/10==7
Console.Write ("Please enter an integer within 100:");
int x = Int. Parse (Console.ReadLine ());
if (x >= 0 && x <= 100)
{
if (x% 7 = = 0)
{
Console.WriteLine ("The number you entered is a multiple of 7");
}
if (x% 10 = = 7)
{
Console.WriteLine ("The number of digits you enter is 7");
}
if (X/10 = = 7)
{
Console.WriteLine ("The Number 10 digits you entered is 7");
}
}
Else
{
Console.WriteLine ("You are not entering an integer within 100");
}

C # input and output, type, operator, statement exercises

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.