Winter Vacation Assignment 1-5

Source: Internet
Author: User

1. Enter three integers, xyz, and eventually output from small to large. Use if nesting.
Console.Write ("Please enter x:");
int x = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter Y:");
int y = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter Z:");
int z = Int. Parse (Console.ReadLine ());
if (x<=y&&x<=z)
{
Console.WriteLine (x);
if (y <= z)
{
Console.WriteLine (y);
Console.WriteLine (z);
}
Else
{
Console.WriteLine (z);
Console.WriteLine (y);
}
}
else if (y <= x && y <= z)
{
Console.WriteLine (y);
if (x <= z)
{
Console.WriteLine (x);
Console.WriteLine (z);
}
Else
{
Console.WriteLine (z);
Console.WriteLine (x);
}
}
Else
{
Console.WriteLine (z);
if (x <= y)
{
Console.WriteLine (x);
Console.WriteLine (y);
}
Else
{
Console.WriteLine (y);
Console.WriteLine (x);
}
}
Console.ReadLine ();


2. Enter three integers, xyz, and eventually output from small to large. Use intermediate variables.
The final output statement is
Console.WriteLine (x+ "," +y+ "," +z ");
Console.WriteLine ("Please enter X");
int x = Int. Parse (Console.ReadLine ());
Console.WriteLine ("Please enter Y");
int y = Int. Parse (Console.ReadLine ());
Console.WriteLine ("Please enter Z");
int z = Int. Parse (Console.ReadLine ());
int a = 0;
int b = 0;
int c = 0;
if (x > Y)
{
A = x;
x = y;
y = A;
}
if (x > Z)
{
b = x;
x = Z;
Z=b;
}
if (Y > Z)
{
c = y;
y = Z;
z = c;
}
Console.WriteLine (x);
Console.WriteLine (y);
Console.WriteLine (z);
Console.ReadLine ();


3. Enter three integers, xyz, and eventually output from small to large. Use the conditional operator.
? :
Ask the previous expression is not established, if you set the value before the colon face
If not, get the value after the colon

Console.Write ("Please enter X");
int x = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter Y");
int y = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter Z");
int z = Int. Parse (Console.ReadLine ());
int a = (x <= y && x <= z)? 1:2;
if (a = = 1)
{
if (y <= z)
{
Console.WriteLine (x + "<" + y + "<" + Z);
}
Else
{
Console.WriteLine (x + "<" + z + "<" + y);
}
}
Else
{
int b = (y <= x && y <= z)? 1:2;
if (b = = 1)
{
if (x <= z)
{
Console.WriteLine (y + "<" + x + "<" + Z);
}
Else
{
Console.WriteLine (y + "<" + z + "<" + x);
}
}
Else
{
if (x <= y)
{
Console.WriteLine (z + "<" + x + "<" + y);
}
Else
{
Console.WriteLine (z + "<" + y + "<" + x);
}
}
}
Console.ReadLine ();


4. "What time is it now?" "Type the number of hours on the keyboard to determine if it is morning or PM.
Print out now what time of the morning or what time of the afternoon. Use the conditional operator.
Console.Write ("Please enter Time:");
int t = Int. Parse (Console.ReadLine ());
if (t >= 0 && T <= 24)
{
String a = (T > 12)? ((t-12) + "p.m.") : (t + "a.m.");
Console.WriteLine (a);
}
Else
{
Console.WriteLine ("Input time is wrong! ");
}
Console.ReadLine ();


5. Blind Date process: Do you have a house? Do you have any money? Do you have the power?
"Get married," "Buy a house before you get married," "Make money before you buy a house, and then get married."
Use if nesting to do the blind date process.
Console.WriteLine ("Do you have a house?" ");
String a = Console.ReadLine ();
if (A = = "has")
{
Console.WriteLine ("Let's Get married!" ");
}
else if (a = = "no")
{
Console.WriteLine ("Are You rich?" ");
String B = Console.ReadLine ();
if (b = = "yes")
{
Console.WriteLine ("Buy a house first, then get married");
}
else if (b = = "No")
{
Console.WriteLine ("Are you capable?" ");
String c = Console.ReadLine ();
if (c = = "has")
{
Console.WriteLine ("Make money before you buy a house and then get Married");
}
else if (c = = "No")
{
Console.WriteLine ("Bye!") ");
}
Else
{
Console.WriteLine ("Wrong input! ");
}
}
Else
{
Console.WriteLine ("Wrong input! ");
}
}
Else
{
Console.WriteLine ("Input Error! ");
}
Console.ReadLine ();

Winter Vacation Assignment 1-5

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.