標籤:and eric 不能 str main names .net int ati
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 第六天_流程語句 8 { 9 class Program10 {11 static void Main(string[] args)12 {13 Random r = new Random(); //1.建立一個能產生隨機數的對象14 while (true)15 {16 int _numR = r.Next(1, 10); //2.讓產生隨機數的這個對象 調用方法來產生隨機數 能取到1到不能取到10,左閉右開區間。17 Console.WriteLine(_numR);18 Console.ReadKey();19 } 20 }21 }22 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 第六天_流程語句 8 { 9 class Program10 {11 static void Main(string[] args)12 {13 Random r = new Random(); //1.建立一個能產生隨機數的對象 14 while (true)15 {16 int _numR = r.Next(1, 7); //2.讓產生隨機數的這個對象 調用方法來產生隨機數 能取到1到不能取到7,左閉右開區間。6種可能17 Console.WriteLine("請輸入您的名字:");18 string _name = Console.ReadLine(); //虛擬碼,對下面操作無影響 19 switch (_numR)20 {21 case 1:22 Console.WriteLine("你上輩子是個大臣");23 break;24 case 2:25 Console.WriteLine("你上輩子是個諸侯");26 break;27 case 3:28 Console.WriteLine("你上輩子是個農民");29 break;30 case 4:31 Console.WriteLine("你上輩子是個王子");32 break;33 case 5:34 Console.WriteLine("你上輩子是個公主");35 break;36 default:37 Console.WriteLine("你上輩子是個侍女");38 break;39 40 }41 Console.ReadKey();42 } 43 }44 }45 }
.Net基礎篇_學習筆記_第七天_隨機數的產生