static void Main(string[] args)
{
int x = 0;
//Write boolean expression to:
bool b1, b2, b3, b4, b5, b6, b7;
//1. Check if x is greater or equal to 9
b1 = (x >= 9);
Console.WriteLine(b1.ToString());
//===================================================
//2. Check if x is not greater than -5
b2 = (x <= -5);
Console.WriteLine(b2.ToString());
//===================================================
//3. Check if x is between -5 and 5
b3 = (x > -5 && x < 5);
Console.WriteLine(b3.ToString());
//===================================================
//4. Check if x is either greater or equal -2 or less than -5
b4 = (x >= -2 || x < -5);
Console.WriteLine(b4.ToString());
//===================================================
//5. Check if x is not equal to 2,4, and 7
b5 = (x != 2 || x != 4 || x != 7);
Console.WriteLine(b5.ToString());
//===================================================
//6. Check if x is equal to 3 or is between 11 and 19 (both not inclusive)
b6 = (x == 3 || x > 11 && x < 19);
Console.WriteLine(b6.ToString());
//===================================================
//7. Check if x is not in the range -11 to 11
b7 = (x < -11 || x > 11);
Console.WriteLine(b7.ToString());
Console.ReadLine();
}
//=================1. Example with Method=====================
static void Main(string[] args)
{
Console.Write("Enter x value: ");
int x = int.Parse(Console.ReadLine());
bool b1 = BooleanMethod(x);
Console.WriteLine(b1);
Console.ReadKey();
}
static bool BooleanMethod(int x)
{
bool b1 = x >= 9;
return b1;
}
}
}
No comments:
Post a Comment