using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 课后提1
{
class Program
{
static void Main(string[] args)
{
// //用户输入姓名,然后打印此人的年龄,从1岁-18岁,每一岁占一行,打印内容为“我今年xxx岁了!”;
//当6岁时增加打印“我上小学了!”;
//当11岁时增加打印“我上初中了!”;
//当15岁时增加打印“我上高中了!”;
//当18岁时增加打印“我成年了!考上了北大!”;
Console.Write("请输入你的姓名:");
string b = Console.ReadLine();
for (int i=1; i<= 18; i++)
{
if (i==6)
{
Console.WriteLine("我叫"+b+",我今年" + i + "岁了,我上小学了!");
}
else if (i == 11)
{
Console.WriteLine("我叫" + b + ",我今年" + i + "岁了,我上初中了!");
}
else if (i == 15)
{
Console.WriteLine("我叫" + b + ",我今年" + i + "岁了,我上高中了!");
}
else if (i == 18)
{
Console.WriteLine("我叫" + b + ",我今年" + i + "岁了,我成年了!我上了北大!");
}
else
{
Console.WriteLine("我叫" + b + ",我今年" + i + "岁了");
}
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 课后题4
{
class Program
{
static void Main(string[] args)
{
//让用户循环操作,用户输入一个正整数(0-20),如果小于0或大于20都提示输入错误,
//如果输入的是0-20之间的数,那么就打印从0到这个数的累加求和,
//一共需要用户输入3遍,输入错误不计入这3遍操作当中
int count = 0;
//让用户循环输入
for (int i = 0; i < 10;i++ )
{
if (count>=3)
{
break;//跳出循环。终止所有的循环。
}
Console.Write("请输入一个正整数(0-20):");
int a = int.Parse(Console.ReadLine());
//判断用户输出的数
if (a >= 0 && a <= 20)
{
//如果输出正确,那么累加求和并输出
int sum = 0;
for (int j = 0; j <= a;j++ )
{
sum += j;
}
Console.WriteLine (sum);
//判断用户当前输入了几遍
count++;
Console.WriteLine("您当前输入第"+count +"遍");
}
else
{
Console.WriteLine("你的输入有误");
}
}
Console.ReadLine();
}
}
}