作业1:定义两个变量如:number1,number2分别赋值为10和5,写程序交换两个变量的值
注:不能使用中间变量
答:
代码
int number1 = 10;
int number2 = 5;
Console.WriteLine("number1=" + number1 + " number2=" + number2);
number1 = number1 + number2;
number2 = number1 - number2;
number1 = number1 - number2;
Console.WriteLine("两个变量的值不使用中间变量交换后:number1=" + number1 + " number2=" + number2);
Console.ReadKey();
运行结果
作业2:请用户输入姓名性别年龄,当用户按下某个键子后在屏幕上显示:您好:XX您的年龄是XX是个X生
答:
代码
Console.WriteLine("请输入您的姓名");
string xingming = Console.ReadLine();
Console.WriteLine("请输入您的年龄");
string nianling = Console.ReadLine();
Console.WriteLine("请输入您的性别");
string xingbie = Console.ReadLine();
Console.WriteLine("您好:{0}您的年龄是{1},是个{2}生", xingming, nianling, xingbie);
Console.ReadKey();
运行结果