Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Posted on October 30, 2025

Table of Contents

  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
    • Multiply of two numbers in Java
      • Using basic multiplication (*) operator
      • Using scanner input
      • Using Recursive method
      • Using constructor
      • Using method with Array
    • Related

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

In this article, we will discuss the concept of Java Code Examples – Multiply Two Numbers in 5 Easy Ways

In this post, we are going to learn how to write a program to 5 Ways to Multiply of Two Numbers (With Examples) in the Java programming language.

Java Code Examples – Multiply Two Numbers in 5 Easy Ways
Java Code Examples – Multiply Two Numbers

Multiply of two numbers in Java

here, I’ll give you separate short programs for each method so it’s easier to understand

Using basic multiplication (*) operator

The simplest and most common way to multiply two numbers

Program 1

// Multiplication of two numbers in Java
// Basic multiplication using * operator
class Basic_Mul {
    public static void main(String[] args) {
        int num1=12; 
        int num2=6;
        System.out.println("product of two numbers: "+(num1*num2));
        
    }
}

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

product of two numbers: 72

 

Using scanner input

The simplest and most common way to multiply two numbers with user input

Program 2

// Multiplication of two numbers in Java
// Basic multiplication using user input
import java.util.Scanner;
class Basic_Multiply {
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in); 
        System.out.print("Enter first number: "); 
        int num1=sc.nextInt(); 
    System.out.print("Enter second number: "); 
        int num2=sc.nextInt();
        System.out.println("product: "+(num1*num2));
        
    }
}

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

Enter first number: 4
Enter second number: 5
product: 20

 

Using Recursive method

Multiply two numbers using recursive method

Program 3

// Multiplication of two numbers in Java
//  Multiplication using recursion
class Mul_Recursion {
  
  public static void main(String[] args) {
   int num1=7;
        int num2=8;
    int product=mul(num1,num2);
        System.out.println("product: "+product);
    }
    public static int mul(int a, int b){
      //recursive method
    if(b==0){
    return 0;
    }else{
    return a+mul(a,b-1);}
    }
    }

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

product: 56

 

Using constructor

Multiply two numbers using constructor

Program 4

// Multiplication of two numbers in Java
//  Multiplication using constructor
class Mul_Cons {
private int result;
//Constructor that takes two nubers and multioly them
public Mul_Cons(int a, int b){
this.result=a*b;
}
  //method for get the result
  public int getResult(){
  return result;
  }
  public static void main(String[] args) {
        int num1=8;
        int num2=10;
    
    //create an object for class
    Mul_Cons mul=new Mul_Cons(num1, num2);
    
    //getting the result and print it
        System.out.println("product of two numbers: "+(mul.getResult()));
    }
    
    }

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

product of two numbers: 80

 

Using method with Array

Multiply two numbers using method with array

Program 5

// Multiplication of two numbers in Java
// Simple Multiplication using method with array

class MultiplyUsingArray {
    public static void main(String[] args) {
   int num1=12;
        int num2=13;
  int[] result=new int[1];
  mul(num1,num2,result);
       
        System.out.println("Product: "+result[0]);
    }
    public static void mul(int a, int b, int[] result){
        result[0]=a*b;
    }
}

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

Product: 156

 

Similar post

C++ program to multiply two numbers using 6 ways

C program to multiply two numbers using 6 ways

JavaScript program to multiply two numbers using 4 ways

PHP multiply two numbers

PHP multiply two numbers using function

 

Pascal code to multiply two numbers in different ways

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes