Calculations

Java program to multiply of two numbers without using arithmetic operator

Java program to multiply of two numbers without using arithmetic operator

problem – Java program to multiply two numbers without using arithmetic operator

 

In this tutorial, we will discuss the concept of multiplying two numbers without using the arithmetic operator in Java language. 

In this post, we will learn how to get the product of two numbers without arithmetic operator in Java programming language

 

multiply two numbers without using arithmetic operator

Java program to find the product of two numbers

Using for loop – Program 1

This program is used to find the multiplication of two numbers entered by the user – using for loop without arithmetic operator

import java.util.Scanner;
class ProductNumWithOutope1{
public static void main(String args[]){
int product=0;
    Scanner scan=new Scanner(System.in); //create a scanner object for input
System.out.print("Enter the first number: ");
int n1=scan.nextInt();//get input from the user for num1
System.out.print("Enter the second number: ");
int n2=scan.nextInt();//get input from the user for num2

for(int i=0; i<n2; i++){
    product=add(product,n1);
}
System.out.print("product of"+n1+"and"+n2+" is: "+product);
}

static int add(int num1,int num2){
for(int i=0; i<num2; i++)
   num1++;
return num1;
}
}

When the above code is executed, it produces the following results

Enter the first number: 30
Enter the second number: 25
Product of 30 and 25 is : 750

 

Using while loop – Program 2

This program is used to find the multiplication of two numbers entered by the user – using while loop without arithmetic operator

import java.util.Scanner;
class ProductNumWithOutope{
public static void main(String args[]){
int product=0;
    Scanner scan=new Scanner(System.in); //create a scanner object for input
System.out.print("Enter the first number: ");
int n1=scan.nextInt();//get input from the user for num1
System.out.print("Enter the second number: ");
int n2=scan.nextInt();//get input from the user for num2

for(int i=0; i<n2; i++){
    product=add(product,n1);
}
System.out.print("product of "+n1+" and "+n2+" is:  "+product);
}

static int add(int num1,int num2){
while(num2 != 0){
int num3=(num1 & num2);
num1=num1^num2;
num2=num3<<1;

}
return num1;

}
}

When the above code is executed, it produces the following results

Enter the first number: 20
Enter the second number: 25
Product of 20 and 25 is : 500

 

Similar program

Java program to Multiply two numbers

C program to multiply two numbers without using arithmetic operator

C++ program to multiply two numbers without using arithmetic operator

Python program to multiply two numbers without using arithmetic operator

C++ find product of two numbers

Python program to multiply two numbers without using arithmetic operator

Python program to multiply two numbers using function

C code to multiply two numbers using function

C# program to multiply two numbers using function

PHP program to multiply two numbers

C# program to multiply two numbers

JavaScript program to multiply two numbers

 

 

Java program to find sum of two numbers without using arithmetic operators

C  program to find sum of two numbers without using arithmetic operators

C++ program to find sum of two numbers without using arithmetic operators

Python program to add two numbers without using arithmetic operators

Java program to sum of two numbers

C program to sum of two numbers

C++ program to sum of two numbers

Python program to sum of two numbers

C++ program to find the sum  of two numbers  using recursion

C program to find the sum  of two numbers  using recursion

Java program to find the sum  of two numbers  using recursion

Python program to find the sum  of two numbers  using recursion

 

Suggested for you

for loop in Java language

while loop in Java language

The method in  Java language

Datatype and variable in Java language

Operator in Java language

 

 

 

 

C++ program to multiply two numbers without using arithmetic operator
Python program to multiply two numbers without using arithmetic operator
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago