java.math.BigInteger multiply()
Description
See also:
Method Syntax
public BigInteger multiply(BigInteger val)
Method Argument
Data Type | Parameter | Description |
---|---|---|
BigInteger | val | value to be multiplied to this BigInteger. |
Method Returns
The multiply(BigInteger val) method returns a BigInteger whose value is (this * val).
Compatibility
Requires Java 1.1 and up
Java BigInteger multiply() Example
Below is a java code demonstrates the use of multiply() method of BigInteger class. The example presented might be simple however it shows the behavior of the multiply() method.
package com.javatutorialhq.java.examples; import java.math.BigInteger; import java.util.Scanner; /* * A java example source code to demonstrate * the use of multiply() method of BigInteger class */ public class BigIntegerMultiplyExample { public static void main(String[] args) { // get user input System.out.print("Enter the first value:"); Scanner s = new Scanner(System.in); String firstInput = s.nextLine(); System.out.print("Enter the second value:"); String secondInput = s.nextLine(); s.close(); // convert the first String Input to BigInteger BigInteger val1 = new BigInteger(firstInput); // convert the second String Input to BigInteger BigInteger val2 = new BigInteger(secondInput); /* * multiply the first value and the second value * using the multiply() method */ BigInteger result = val1.multiply(val2); System.out.println("Result = "+result); } }
This example is a lot simpler than it looks. Basically we ask for user input and converted this value into BigInteger. The two values entered by the user which has been converted to BigInteger is multiplied using the multiply() method. The quotient is printed at the end of the code.