Java Multiplication

Java Multiplication Arithmetic operator takes two operands as inputs and returns the difference of right operand from left operand.

* symbol is used for Multiplication Operator.

Syntax – Multiplication Operator

Following is the syntax for Multiplication Operator.

</>
Copy
result = 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.

Example 1 – Multiply two Integers

In the following example, we shall take two integers and apply Multiplication operation to find the product of the two numbers.

Java Program

</>
Copy
public class MultiplicationExample {
	public static void main(String[] args) {
		int a = 8;
		int b = 3;
		
		int result = a * b;
		System.out.print(result);
	}
}

Output

24

Example 2 – Multiply two Numbers of Different Datatypes

In the following example, we shall find the difference of an integer and a float using Multiplication Arithmetic Operator.

As the operand values are of two different datatypes, Java promotes the value with lower datatype to higher datatype and the result would be of higher datatype. In the following example, int is promoted to float, and the result is a floating point number.

Java Program

</>
Copy
public class MultiplicationExample {
	public static void main(String[] args) {
		int a = 8;
		float b = 3.4f;
		
		float result = a * b;
		System.out.print(result);
	}
}

Output

27.2

Conclusion

In this Java Tutorial, we learned how to use Java Multiplication Operator.