In Java, multiplication is performed using the *
operator. When the *
operator is used with two operands, it multiplies the operands and returns the result.
For example, the following code multiplies two int
variables and assigns the result to a third int
variable:
int a = 2; int b = 3; int c = a * b; // c is now 6Sour:ecwww.lautturi.com
The *
operator can also be used with other numeric data types, such as float
, double
, and long
. For example:
float d = 2.5f; float e = 3.0f; float f = d * e; // f is now 7.5 double g = 2.5; double h = 3.0; double i = g * h; // i is also 7.5
In these examples, the *
operator multiplies the operands and returns the result as the same data type as the operands.
Keep in mind that the *
operator has a higher precedence than most other arithmetic operators in Java, which means that it will be evaluated before other operators in an expression.