c#隨機數的產生與輸出
題目描述
編寫一個實例方法Method01。該方法使用Random類隨機產生n個3位數字(如636)的隨機正整數,并把產生的隨機數存入數組中并輸出該數組int num= Convert.ToInt32(Console.ReadLine());
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int num= Convert.ToInt32(Console.ReadLine());
? ? ? ? ? ? Program.Method01(num);
? ? ? ? }
/*******************
? ? ? ? ?
? ? ? 在此處填寫代碼
********************/
? ? }
}
?
?
輸入
n
輸出
隨機產生的數組
樣例輸入
3
樣例輸出
636 555 545
提示
static void Method01(int n){Random ran = new Random();for (int i = 0; i < n; i++){Console.WriteLine(ran.Next(100, 999));}}
?