VR引擎程序设计-Day03

36 阅读1分钟

if-else

int score = Convert.ToInt32(Console.ReadLine());
if (score < 0 || score > 100)
{
    Console.WriteLine("输入错误");
    return;
}
if (score >= 90 && score <= 100)
{
    Console.WriteLine("A");
}
else if (score >= 70 && score <= 89)
{
    Console.WriteLine("B");
}
else if (score >= 60 && score <= 69)
{
    Console.WriteLine("C");
}
else
{
    Console.WriteLine("D");
}

字符转ascll码

Console.WriteLine(Convert.ToInt32('A'));

switch

//每星期日程

 string day = Console.ReadLine();
 switch (day) {
     case "1":
         Console.WriteLine("马原 let's go!");
         break;
     case "2":
         Console.WriteLine("Python Oh no!");
         break ;
     case "3":
         Console.WriteLine("C++ Hi!");
         break;
     case "4":
         Console.WriteLine("数据结构 Haha!");
         break;
     case "5":
         Console.WriteLine("C# Happy!");
         break;
     case "6":
         Console.WriteLine("休息!");
         break;
     case "7":
         Console.WriteLine("休息!");
         break;
     default:
         break;
 }

输入4个整数,求最大值、最小值

int a = Convert.ToInt32(Console.ReadLine());
int max = a, min = a;
int b = Convert.ToInt32(Console.ReadLine());
if(b > max) max = b;
if(b < min) min = b;
int c = Convert.ToInt32(Console.ReadLine());
if (c > max) max = c;
if (c < min) min = c;
int d = Convert.ToInt32(Console.ReadLine());
if (d > max) max = d;
if (d < min) min = d;
Console.WriteLine("最大值:{0}", max);
Console.WriteLine("最小值:{0}", min);