Show 例子 2
优质
小牛编辑
140浏览
2023-12-01
例子 (Example)
以下示例显示如何在Dart中使用Equality和Relational运算符 -
void main() {
var num1 = 5;
var num2 = 9;
var res = num1>num2;
print('num1 greater than num2 :: ' +res.toString());
res = num1<num2;
print('num1 lesser than num2 :: ' +res.toString());
res = num1 >= num2;
print('num1 greater than or equal to num2 :: ' +res.toString());
res = num1 <= num2;
print('num1 lesser than or equal to num2 :: ' +res.toString());
res = num1 != num2;
print('num1 not equal to num2 :: ' +res.toString());
res = num1 == num2;
print('num1 equal to num2 :: ' +res.toString());
}
它将产生以下output -
num1 greater than num2 :: false
num1 lesser than num2 :: true
num1 greater than or equal to num2 :: false
num1 lesser than or equal to num2 :: true
num1 not equal to num2 :: true
num1 equal to num2 :: false