CSharp examples for Language Basics:int
Comparing integers using if statements, equality operators, and relational operators.
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}"); } } }