VelizarAvramov

09. Count the Integers

Nov 5th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09._Count_the_Integers
  4. {
  5.     class CountIntegers
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Write a program, which can receive any type of input, but upon receiving anything other than an integer – stops the
  10.             //execution of the program and prints how many numbers were read.
  11.             int counter = 0;
  12.             try
  13.             {
  14.                 while (true)
  15.                 {
  16.                     int input = int.Parse(Console.ReadLine());
  17.                     counter++;
  18.                 }
  19.             }
  20.             catch (Exception)
  21.             {
  22.                 Console.WriteLine(counter);              
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment