VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • C# Random(2)

输出结果,如图所示:

 

【实例】输入名字随机显示这个人上辈子是什么样的人

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Program
  {
      static void Main(string[] args)
      {   //随机数
          Random rd = new Random();         
          while (true)
          {
              int number = rd.Next(1, 6);
              Console.WriteLine("请输入你的名字");
              string name = Console.ReadLine();
              if (name=="")
              {
                  Console.WriteLine("名字不能为空,请重新输入你的名字");
                  name = Console.ReadLine();
              }             
              switch (number)
              {
                  case 1:
                      Console.WriteLine("{0}的上辈子是皇帝", name);
                      break;
                  case 2:
                      Console.WriteLine("{0}的上辈子是皇后", name);
                      break;
                  case 3:
                      Console.WriteLine("{0}的上辈子是贵妃", name);
                      break;
                  case 4:
                      Console.WriteLine("{0}的上辈子是秀才", name);
                      break;
                  case 5:
                      Console.WriteLine("{0}的上辈子是驸马", name);
                      break;
              }
              Console.ReadKey();
          }
      }
  }

相关教程