Comparing integers using if statements, equality operators, and relational operators. - CSharp Language Basics

CSharp examples for Language Basics:int

Description

Comparing integers using if statements, equality operators, and relational operators.

Demo Code

using System;//  w  w  w  . j  a v a 2  s .  co  m
class Comparison
{
   static void Main()
   {
      // prompt user and read first number
      Console.Write("Enter first integer: ");
      int number1 = int.Parse(Console.ReadLine());
      // prompt user and read second number
      Console.Write("Enter second integer: ");
      int number2 = int.Parse(Console.ReadLine());
      if (number1 == number2)
      {
         Console.WriteLine($"{number1} == {number2}");
      }
      if (number1 != number2)
      {
         Console.WriteLine($"{number1} != {number2}");
      }
      if (number1 < number2)
      {
         Console.WriteLine($"{number1} < {number2}");
      }
      if (number1 > number2)
      {
         Console.WriteLine($"{number1} > {number2}");
      }
      if (number1 <= number2)
      {
         Console.WriteLine($"{number1} <= {number2}");
      }
      if (number1 >= number2)
      {
         Console.WriteLine($"{number1} >= {number2}");
      }
   }
}

Result


Related Tutorials