Multiplication Operator

Dart Arithmetic Multiplication Operator takes two numbers as operands and returns their product.

Symbol

* symbol is used for Multiplication Operator.

Syntax

The syntax for Multiplication Operator is

</>
Copy
operand_1 * operand_2

The operands could be of any numeric datatype.

If the two operands are of different datatypes, implicit datatype promotion takes place and value of lower datatype is promoted to higher datatype.

Examples

Multiplication of Integers

In the following example, we read two integers from user, and find their product using Arithmetic Multiplication Operator.

main.dart

</>
Copy
import 'dart:io';

void main() {
    print('Enter n1');
    var n1 = int.parse(stdin.readLineSync()!);
    print('Enter n2');
    var n2 = int.parse(stdin.readLineSync()!);

    var output = n1 * n2;

    print('n1 * n2 = $output');
}

Output

Enter n1
8
Enter n2
6
n1 * n2 = 48

Multiplication of Double Values

In the following example, we read two double values from user, and find their product using Arithmetic Multiplication Operator.

main.dart

</>
Copy
import 'dart:io';

void main() {
    print('Enter n1');
    var n1 = double.parse(stdin.readLineSync()!);
    print('Enter n2');
    var n2 = double.parse(stdin.readLineSync()!);
 
    var output = n1 * n2;
 
    print('n1 * n2 = $output');
}

Output

Enter n1
3.14
Enter n2
5.1
n1 * n2 = 16.014

Conclusion

In this Dart Tutorial, we learned how to use Arithmetic Multiplication Operator to multiply given two numbers.