public static void Task01()
{
int sum = 0;
for (int i = 2; i < 101; i++)
{
if (IsPrime(i))
{
sum += i;
}
}
Console.WriteLine("1—100内的所有质数的和为{0}", sum);
}
static bool IsPrime(int r)
{
for (int i = 2; i <= r / 2; i++)
{
if (r % i == 0)
{
return false;
}
}
return true;
}
public static void Task02()
{
Console.WriteLine("请输入要打印的行数");
int lines = int.Parse(Console.ReadLine());
for (int i = 1; i <= lines; i++)
{
for (int j = 0; j < 2 * i; j++)
{
Console.Write((char)('A' + i - 1));
}
Console.WriteLine();
}
}
public static void Task03()
{
string str = "sffsDdssgCHHJHVJHVJHDDSDFGdg";
Console.WriteLine("大小写翻转后为{0}", Conversion(str));
}
static string Conversion(string str)
{
char word;
string words = string.Empty;
for (int i = 0; i < str.Length; i++)
{
word = str[i];
if (word >= 'A' && word < 'Z')
{
words += char.ToLower(word);
}
else if (word >= 'a' && word < 'z')
{
words += char.ToUpper(word); ;
}
}
return words;
}
public static void Task04()
{
Random ran = new Random();
Console.WriteLine("第一个随机数组:");
int[] numberArr1 = new int[ran.Next(5, 11)];
for (int i = 0; i < numberArr1.Length; i++)
{
int a = ran.Next(1, 10);
if (!(IsContains(a, numberArr1)))
{
numberArr1[i] = a;
}
}
Show(numberArr1);
Console.WriteLine("第二个随机数组:");
int[] numberArr2 = new int[ran.Next(5, 11)];
for (int i = 0; i < numberArr2.Length; i++)
{
int b = ran.Next(1, 10);
if (!(IsContains(b, numberArr2)))
{
numberArr2[i] = b;
}
}
Show(numberArr2);
int bigLength = 0;
int smallLength = 0;
if (numberArr1.Length > numberArr2.Length)
{
smallLength = numberArr2.Length;
bigLength = numberArr1.Length;
}
else
{
bigLength = numberArr2.Length;
smallLength = numberArr1.Length;
}
int[] resultArr = new int[bigLength];
for (int i = 0; i < smallLength; i++)
{
resultArr[i] = numberArr1[i] + numberArr2[i];
}
for (int i = smallLength; i < bigLength; i++)
{
if (numberArr1.Length > numberArr2.Length)
{
resultArr[i] = numberArr1[i];
}
else
{
resultArr[i] = numberArr2[i];
}
}
Console.WriteLine("合并后的结果为:");
Show(resultArr);
}
static bool IsContains(int number, int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == number)
{
return true;
}
}
return false;
}
static void Show(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write("{0} ", arr[i]);
}
Console.WriteLine();
}
public static void Task05()
{
Console.WriteLine("请输入一个大于二的整数,回车键得到相应的斐波那契数");
int num = int.Parse(Console.ReadLine());
Console.WriteLine(FabniceNumber(num));
}
static int FabniceNumber(int num)
{
int[] number = new int[num + 1];
number[0] = 1;
number[1] = 1;
for (int i = 2; i < num + 1; i++)
{
number[i] = number[i - 1] + number[i - 2];
}
return number[num];
}
public static void Task06()
{
Console.WriteLine("请输入需要打印的杨辉三角的行数");
int num = int.Parse(Console.ReadLine());
int[,] arr = new int[num, num];
for (int i = 0; i < num; i++)
{
for (int j = 0; j < num - i; j++)
{
Console.Write(" ");
}
for (int j = 0; j <= i; j++)
{
arr[i, j] = j == 0 || j == i ? 1 : arr[i - 1, j] + arr[i - 1, j - 1];
Console.Write(arr[i, j].ToString() + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
public static void Task07()
{
string str = "afH856";
int numberCount = 0;
int bigWordsCount = 0;
int smallWordsCount = 0;
Count(str, out bigWordsCount, out smallWordsCount,out numberCount);
Console.WriteLine("{0}中有大写字母{1}个,小写字母{2}个,数字{3}个", str, bigWordsCount, smallWordsCount, numberCount);
}
static void Count(string str, out int bigWordsCount, out int smallWordsCount ,out int numberCount)
{
numberCount = 0;
bigWordsCount = 0;
smallWordsCount = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= 'A' && str[i] < 'Z')
{
bigWordsCount++;
}
else if (str[i] >= 'a' && str[i] < 'z')
{
smallWordsCount++;
}
else if (str[i] >= '0' && str[i] <= '9')
{
numberCount++;
}
}
}
public static void Task08()
{
Student[] stu = new Student[5];
stu[0] = new Student("小明", 23, "河南省", "郑州");
stu[1] = new Student("小红", 25, "河北省", "石家庄");
stu[2] = new Student("小张", 33, "河南省", "开封");
stu[3] = new Student("小李", 43, "山东省", "济南");
stu[4] = new Student("小宋", 28, "山东省", "聊城");
Console.WriteLine("-----------------------------");
ProvinceShow(stu, "山东省");
ProvinceShow(stu, "河北省");
ProvinceShow(stu, "河南省");
Console.WriteLine("-----------------------------");
CityShow(stu, "开封");
CityShow(stu, "济南 ");
CityShow(stu, "石家庄");
}
static void ProvinceShow(Student[] arr, string province)
{
for (int i = 0; i < arr.Length; i++)
{
if (province == arr[i].Province)
{
arr[i].Show();
}
}
}
static void CityShow(Student[] arr, string city)
{
for (int i = 0; i < arr.Length; i++)
{
if (city == arr[i].City)
{
arr[i].Show();
}
}
}
public static void Task09()
{
Sphere s = new Sphere(3.2, 2.2, 3.3, 4.4);
s.GetVolume(s.Radius);
Sphere q = new Sphere(4.5, 1.8, 4.9, 5.3);
s.GetInfo(s, q);
}
public static void Task10()
{
Player player = new Player("亚瑟", "野蛮人", 800, 100, 50, "正常");
Player enemy = new Player("虞姬", "法师", 800, 100, 50, "正常");
Random random = new Random();
int count = 1;
while (true)
{
Console.WriteLine("------------第{0}回合---------------", count);
player.PlayerAttack(enemy, random.Next(1, 5));
enemy.ToString1();
if (enemy._Hp <= 0)
{
Console.WriteLine("虞姬牺牲了");
break;
}
else
{
Console.WriteLine("虞姬还有{0}血", enemy._Hp);
}
Console.WriteLine("***************");
enemy.EnemyAttack(player);
player.ToString2();
if (player._Hp <= 0)
{
Console.WriteLine("亚瑟玩完了");
break;
}
else
{
Console.WriteLine("亚瑟还有{0}血", player._Hp);
}
count++;
Console.WriteLine();
Console.WriteLine();
}