Dart 编程 - 算术运算符



示例

以下示例演示如何在 Dart 中使用不同的运算符 −

void main() { 
   var num1 = 101; 
   var num2 = 2; 
   var res = 0; 
   
   res = num1+num2; 
   print("Addition: ${res}"); 
   
   res = num1-num2;
   print("Subtraction: ${res}"); 
   
   res = num1*num2; 
   print("Multiplication: ${res}"); 
   
   res = num1/num2; 
   print("Division: ${res}"); 
   
   res = num1~/num2; 
   print("Division returning Integer: ${res}"); 
   
   res = num1%num2; 
   print("Remainder: ${res}"); 
   
   num1++; 
   print("Increment: ${num1}"); 
   
   num2--; 
   print("Decrement: ${num2}"); 
}

它将产生以下输出 −

Addition:103 
Subtraction: 99                               
Multiplication: 202               
Division: 50.5
Division returning Integer: 50                  
Remainder: 1      
Increment: 102    
Decrement: 1
dart_programming_operators.htm
广告