Read int from console - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Read int from console

Demo Code

using System;//  w w  w  .j  a  v a2s  .  com

class MainClass
{
   static void Main()
   {
      // get numerator
      Console.Write("Please enter an integer numerator: ");
      var numerator = int.Parse(Console.ReadLine());

      // get denominator
      Console.Write("Please enter an integer denominator: ");
      var denominator = int.Parse(Console.ReadLine());

      // divide the two integers, then display the result
      var result = numerator / denominator;
      Console.WriteLine($"\nResult: {numerator} / {denominator} = {result}");
   }
}

Result


Related Tutorials