第十二节 流程控制(二)
逻辑表达式:比较两值大小关系的运算符称为关系变量。
关系运算符可以和其它运算符一起构成逻辑表达式。

(10 + 5) >= 10;
左操作数 关系运算符 右操作数
关系运算符“==”比较左右两个操作数是否相等。
赋值运算符“=”将右边的值赋值给左边。
逻辑运算符。
&&(且)。两者都为真时,结果才为真。

||(或)。一真则真。

(!)非

优先级

布尔变量:真假 结果。true,false; 用关键字bool声明。 bool isEvern=true;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SuanShu1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(15+8>=20);
Console.WriteLine(12%2==0);
Console.WriteLine(10/4==5);
//n是大于20的偶数。
int n = 40;
Console.WriteLine((n > 20) && (n % 2 == 0));
//n是7的倍数或是9的倍数
double n1 = 90;
Console.WriteLine((n1%7==0)||(n1%9==0));
double n2 = 8;
Console.WriteLine(!(n2!=8));
// Bool类型
bool x;
x = (6+2>7);
Console.WriteLine(x);
bool y;
y=false;
Console.WriteLine(y);
int z;
z = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(((z%4==0&&(z%100!=0))||(z%400==0)));
}
}
}
浙公网安备 33010602011771号