Multiply of two numbers without using operator in java
In the below program we are going to see how to multiply of two numbers without using operator i.e; finding the product of two numbers without using * operator in java programming language.
In the below program we are going to read two numbers using command line argument. So while running the program we have to pass two values.
Here we took three variable by name a, b, product. variables a,b will hold the values and variable product will hold the product of two numbers.
class multiply{
public static void main (String args[]){
int a, b, product=0;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
int i=0;
while(i<b){
product= product + a;
i++;
}
System.out.println("First number = " + a);
System.out.println("Second number = " + b);
System.out.println(" Multiply of two numbers without using operator = " + product);
}
}