Saturday, March 1, 2014

Boolean01: (Wk-2), Jan 16, 2014

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BooleanExpression01
{
    class Program
    {
        static void Main(string[] args)
        {
            //Boolean Type: bool (or Boolean)
            //Boolean Values: true, false
            //Boolean Variables: bool x; bool y;
            //Realational Operators
            //Boolean expression


            int x = 19;
            int y = 45;

            bool b1, b2, b3, b4, b5, b6;
            b1 = (x > y); //is x greater than y?
            b2 = (x < y); //is x less than y?
            b3 = (x == y); //is x equal to y?
            b4 = (x != y); //is x not equal to y?
            b5 = (x >= y); //is x greater or equal to y?
            b6 = (x <= y); //is x less than or equal to y?

            //C# execute the right-hand side expression (x>y) by asking:
            //is x greater than y, or
            //is 45 greater than 19
            //the answer is false.
            //So b1 is assigned the value false.

            Console.WriteLine("x= {0}   y = {1}", x, y);
            Console.WriteLine();//skip a line

            Console.WriteLine("is x > y?: " + b1);
            Console.WriteLine("is x < y?: " + b2);
            Console.WriteLine("is x == y?: " + b3);
            Console.WriteLine("is x != y?: " + b4);
            Console.WriteLine("is x >= y?: " + b5);
            Console.WriteLine("is x <= y?: " + b6);

            Console.ReadLine(); //pause
        }
    }
}

No comments:

Post a Comment