Advertisement
Guest User

Read20Chars.cs

a guest
Feb 1st, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2.  
  3. class Read20Chars
  4. {
  5.     static void Main()
  6.     {
  7.         try
  8.         {
  9.             Console.Write("Enter word not more than 20 chars long: ");
  10.             string input = Console.ReadLine();
  11.  
  12.             if (input.Length > 20) throw new IndexOutOfRangeException();
  13.             else Console.WriteLine(input += new string('*', 20 - input.Length));
  14.         }
  15.         catch (IndexOutOfRangeException)
  16.         {
  17.             Console.WriteLine("String too long!");
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement