Advertisement
renurtt

Untitled

Apr 10th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. namespace Files_for_cw
  2. {
  3.     using System;
  4.     using System.IO;
  5.  
  6.     internal class Program
  7.     {
  8.         private static Random rnd = new Random();
  9.  
  10.         public static void Main(string[] args)
  11.         {
  12.             do
  13.             {
  14.                 string path = @"../../../input.txt";
  15.                 int N = ReadN();
  16.                 try
  17.                 {
  18.                     using (StreamWriter stream = new StreamWriter(path))
  19.                     {
  20.                         for (int i = 0; i < N; i++)
  21.                         {
  22.                             stream.WriteLine(rnd.Next(0, 1000));
  23.                         }
  24.                     } // using
  25.                 }
  26.                 catch (Exception e)
  27.                 {
  28.                     Console.WriteLine(e.Message);
  29.                 }
  30.  
  31.                 Console.WriteLine("Нажмите любую клавишу, чтобы повторить или Эскейп, чтобы выйти.");
  32.             } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  33.         }
  34.  
  35.         private static int ReadN()
  36.         {
  37.             Console.WriteLine("Введите количество чисел:");
  38.             int N;
  39.             while (!int.TryParse(Console.ReadLine(), out N))
  40.             {
  41.                 Console.WriteLine("Попробуйте еще разок:");
  42.             }
  43.  
  44.             return N;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement