Menu
Coddy logo textTech

Arithmetic Operators

Part of the Fundamentals section of Coddy's Dart journey — lesson 16 of 94.

Arithmetic operators in Dart perform mathematical calculations: addition (+), subtraction (-), multiplication (*), and division (/).

void main() {
  int num1 = 10;
  int num2 = 5;
  int sum = num1 + num2;
  
  print('Sum: $num1 + $num2 = $sum');
}
void main() {
  int num1 = 10;
  int num2 = 5;
  int difference = num1 - num2;
  
  print('Difference: $num1 - $num2 = $difference');
}
void main() {
  int num1 = 10;
  int num2 = 5;
  int product = num1 * num2;
  
  print('Product: $num1 * $num2 = $product');
}
void main() {
  int num1 = 10;
  int num2 = 5;
  double quotient = num1 / num2;
  
  print('Quotient: $num1 / $num2 = $quotient');
}
void main() {
  int intValue = 5;
  double doubleValue = 2.5;
  double result = intValue + doubleValue;
  
  print('$intValue + $doubleValue = $result');
}
challenge icon

Challenge

Beginner

Create a Dart program that performs basic arithmetic operations:

  1. Declare an integer variable named num1 with a value of 10
  2. Declare an integer variable named num2 with a value of 5
  3. Calculate and store the following operations in appropriately named variables:
    • The sum of num1 and num2 (store in sum)
    • The difference when num2 is subtracted from num1 (store in difference)
    • The product of num1 and num2 (store in product)
    • The result when num1 is divided by num2 (store in quotient as a double)
  4. Print each result with the EXACT following format:
Sum: 15
Difference: 5
Product: 50
Quotient: 2.0

Your output must match this exact format.

Cheat sheet

Dart supports four basic arithmetic operators:

  • + for addition
  • - for subtraction
  • * for multiplication
  • / for division
int num1 = 10;
int num2 = 5;
int sum = num1 + num2;        // 15
int difference = num1 - num2;  // 5
int product = num1 * num2;     // 50
double quotient = num1 / num2; // 2.0

You can mix int and double types in arithmetic operations:

int intValue = 5;
double doubleValue = 2.5;
double result = intValue + doubleValue; // 7.5

Try it yourself

void main() {
  // Declare your variables here
  int num1 = ?;
  int num2 = ?;
  
  // Perform arithmetic operations
  int sum = ?;
  int difference = ?;
  int product = ?;
  double quotient = ?;
  
  // Print the results
  print("Sum: $sum");
  print("Difference: $difference");
  print("Product: $product");
  print("Quotient: $quotient");
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals