Java program to perform multiplication of two number without using * operator

Java program to perform multiplication of two number without using * operator

 

Java supports different types of Operators. Operators can be classified into numbers of categories: Arithmetic operators, Bitwise operators, Logical Operators, Conditional operators, Assignment Operators, Relational operators, Special operators, Increment Operators, Decrement operators. Java program to perform multiplication of two number without using * operator are given below:

Arithmetic Operators:

Arithmetic operators are addition, substraction, multiplication, division, and modulus. The symbol modulus (%) which divides one operand by another and returns the remainder as its output.

The following table lists the arithmetic operators:

Operator Meaning
    +  Addition or unary plus
     – Substraction or unary minus
     * Multiplication
     /  Division
     %  Modulus

Program:

import java.io.*;
import java.util.*;
class Multiplication{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the 1st number");
int a=sc.nextInt();
System.out.println("Enter the 2nd number");
int b=sc.nextInt();
 int c=0;
for(int i=0;i<b;i++)
{
c=c+a;
}
System.out.println("The Multiplication of two numbers is "+c);
}
}

Compile:

javac Multiplication.java

Run:

java Multiplication

Output:

Enter the 1st number
10
Enter the 2nd number
5
The Multiplication of two numbers is 50

 

The Process of programming in java is divided into 3 phases:

  • 1. Writing Simple Java Program: Create a simple java Program by typing it into a text editor. Then save the program with the same name as that of the class name. You can wrote simple java application in Eclipse also.
  • 2. Compiling a Java Source File: After Completion of Java program, open Command prompt. Type the Command “ javac filename.java ” . If their is  any error then remove first.
  • 3. Running a Java Application: To run java Application in the command prompt ,type ” Filename.java” .

 

Recommended Post:

1. Difference between Class and Object in java?

2. Java program to perform multiplication of two numbers without using * operator.

3. Java program to calculate Area and Circumference of Circle.

4. Java Program to calculate addition and substraction of two numbers.

5. Java program to calculate multiplication of two numbers using 5 different ways.