In this section, we will learn how to multiply two numbers without using the arithmetic operator (*) in Java.

You are watching: Multiply 2 numbers without using multiplication operator

The multiplication of two numbers can be found by the repeated addition method. It means that add the number (multiplicand) into itself up to multiplicator times. The method can be used if we want to calculate the multiplication of small numbers.

Suppose, we want to multiply 3 by 4 which gives 12 as the result. The same can be achieved by adding 3 four times i.e. (3 + 3 + 3 + 3 = 12) or by adding 4 three times i.e. (4 + 4 + 4 = 12). Both give the same result. Therefore, we can implement the logic using recursion.

Using for Loop

MultiplicationExample1.java


import java.util.Scanner;public class MultiplicationExample1{public static void main(String args<>) {Scanner sc=new Scanner(System.in);int x, y, sum=0;System.out.print("Enter the first number: ");x=sc.nextInt();System.out.print("Enter the second number: ");y=sc.nextInt();//executes until the condition becomes falsefor(int i=1;i

Output:


Enter the first number: 6Enter the second number: 16The multiplication of 6 and 16 is: 96
Let"s see another logic for the same.

MultiplicationExample2.java


import java.util.Scanner;public class MultiplicationExample2{public static void main(String args<>){int product=0;Scanner scan=new Scanner(System.in); System.out.print("Enter the first number: ");int multiplicand = scan.nextInt();System.out.print("Enter the second number: ");int multiplicator = scan.nextInt();for(int i=0; i

Output:


Enter the first number: 37Enter the second number: 23product of 37 and 23 is: 851

Using while Loop

MultiplicationExample3.java


import java.util.Scanner;public class MultiplicationExample3{public static void main(String args<>){int product=0; Scanner scan = new Scanner(System.in); System.out.print("Enter the multiplicand: ");//reads an integer from the userint multiplicand = scan.nextInt();System.out.print("Enter the multiplicator: ");//reads an integer from the userint multiplicator=scan.nextInt();for(int i=0; i

Output:


Enter the multiplicand: 17Enter the multiplicator: 8The product of 17 and 8 is: 136

Using Recursion

By using the recursion, we can multiply two integers with the given constraints.To multiply a and b, recursively add a, b time.

See more: What Does Srsly Mean In Texting ? What Does Srsly Mean

Integers include both positive and negative numbers. The multiplier or multiplicand may hold a positive or a negative sign before the number. No sign before a number represents a positive number. If the number holds a positive or a negative sign, they follow the rules, given in the following table.

*
For Videos Join Our Youtube Channel: Join Now

Feedback

Help Others, Please Share

*
React Native


*

Python Design Patterns


*

Python Pillow


*

Python Turtle


*

Keras


*

Kibana


*

Mean Stack


*

Microprocessor


*

Mobile Computing


*

Mobile Testing


*

Nagios


*

Nifi


*

Online Marketing


*

OpenStack


*

PDF


Preparation


*

Aptitude


*

Reasoning


*

Verbal Ability


*

Interview Questions


*

Company Questions


Trending Technologies


*

Artificial Intelligence


*

AWS


*

Selenium


*

Cloud Computing


*

Hadoop


*

ReactJS


*

Data Science


*

Angular 7


*

Blockchain


*

Git


*

Machine Learning


*

DevOps


B.Tech / MCA


*

DBMS


*

Data Structures


*

DAA


*

Operating System


*

Computer Network


*

Compiler Design


*

Computer Organization


*

Discrete Mathematics


*

Ethical Hacking


*

Computer Graphics


*

Software Engineering


*

Web Technology


*

Cyber Security


*

Automata


*

C Programming


*

C++


*

Java


*

.Net


*

Python


*

Programs


*

Control System


*

Data Mining


*

Data Warehouse


dearteassociazione.org Services

dearteassociazione.org offers too many high quality services. Mail us on , to get more information about given services.

Website DesigningWebsite DevelopmentJava DevelopmentPHP DevelopmentWordPressGraphic DesigningLogoDigital MarketingOn Page and Off Page SEOPPCContent DevelopmentCorporate TrainingClassroom and Online TrainingData Entry


Training For College Campus

dearteassociazione.org offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at Duration: 1 week to 2 week


Like/Subscribe us for latest updates or newsletter
*
*
*
*
*
*

Learn Tutorials

Learn JavaLearn Data StructuresLearn C ProgrammingLearn C++ TutorialLearn C# TutorialLearn PHP TutorialLearn HTML TutorialLearn JavaScript TutorialLearn jQuery TutorialLearn Spring Tutorial

Our Websites

dearteassociazione.orgHindi100.comLyricsia.comQuoteperson.comJobandplacement.com

Our Services

Website Development

Android Development

Website Designing

Digital Marketing

Summer Training

Industrial Training

College Campus Training


Contact

Address: G-13, 2nd Floor, Sec-3

Noida, UP, 201301, India

Contact No: 0120-4256464, 9990449935

Contact Us Subscribe Us Privacy PolicySitemapAbout Me