Java multipy, add, subtract, divide two numbers without using operators - Java @ Desk

Friday, October 4, 2013

Java multipy, add, subtract, divide two numbers without using operators

Java multipy, add, subtract, divide two numbers without using operators In Java, following operators are used to perform mathematical operations:
1) + - Addition
2) - - Subtraction
3) * - Multiplication
4) / - Division

One can multiply, add, subtract and divide in java without the usage of above operators using the java.math.BigInteger class. This class has methods add(), subtract(), multiply() and divide().

Implementated below :
import java.math.BigInteger;

public class Multiply {

    public static void main(String args[]) {

        int number1 = 200;
        int number2 = 100;

        System.out.println(new BigInteger(String.valueOf(number1)).multiply(new BigInteger(String.valueOf(number2))));
        System.out.println(new BigInteger(String.valueOf(number1)).add(new BigInteger(String.valueOf(number2))));
        System.out.println(new BigInteger(String.valueOf(number1)).subtract(new BigInteger(String.valueOf(number2))));
        System.out.println(new BigInteger(String.valueOf(number1)).divide(new BigInteger(String.valueOf(number2))));
        
    }
}






1 comment:

  1. If some one wants expert view regarding blogging after that
    i suggest him/her to go to see this webpage, Keep up the pleasant
    job.

    Here is my website ... colchones barcelona -
    -

    ReplyDelete