Use if-else statement to check number range - CSharp Language Basics

CSharp examples for Language Basics:if

Description

Use if-else statement to check number range

Demo Code

using System;//from  w ww . ja v a2  s  .  c o m
public class StatementTest {
   public static void Main( ) {
      int i = 8;
      if( (i >= 1) && (i <= 10) ) {
         if( (i % 2) == 0 )
         {
            Console.WriteLine("The number {0} is even", i );
         }
         else
         {
            Console.WriteLine("The number {0} is odd", i );
         }
      } else
      {
         Console.WriteLine("You must enter a number between 1 and 10");
      }
   }
}

Result


Related Tutorials