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

Multiply two numbers in Java using scanner| 5 different ways

Posted on November 26, 2025November 26, 2025

Table of Contents

  • Multiply two numbers in Java using scanner| 5 different ways
    • Different Ways to multiplication
      • Multiply two numbers in Java using scanner
      • Multiply two numbers in Java using Method
      • Multiply two numbers in using constructor
      • Multiply two numbers in using recursion
      • Multiply two numbers in using for loop
    • Related

Multiply two numbers in Java using scanner| 5 different ways

In this article, we will discuss the concept of Java Code Examples – Multiply two numbers in Java using scanner| 5 different ways

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

Multiply two numbers in Java using scanner| 5 different ways
Multiplication Two Numbers

Different Ways to multiplication

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

 

Program 1

Multiply two numbers in Java using scanner

Multiplication of two numbers using multiplication (*) operator with user input. The simplest and most common way to Multiplication of two numbers

// Multiplication of two numbers in Java
// Basic multiplication using * operator
import java.util.Scanner;
class Basic_Multiplication{
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in); 
        System.out.print("Input first number: "); 
        int num_1=sc.nextInt(); 
    System.out.print("Input second number: "); 
        int num_2=sc.nextInt();
        System.out.println("Multiplication of two numbers: "+
        (num_1*num_2));
        
    }
}

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

Input first number: 7
Input second number: 9
Multiplication of two numbers: 63

 

Multiply two numbers in Java using Method

Multiplication of two numbers using user defined method with user input.

Program 2

//Multiplication of two numbers 
//in Java programming using a method
import java.util.Scanner;
class MulTwoNum{
    public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
 System.out.println("Input value for num1:");
int num1=input.nextInt();

 System.out.println("Input value for num2:");
int num2=input.nextInt();
        int mul=mulNum(num1,num2);
        System.out.println("The Multiplication is: "+mul);
    }
    public static int mulNum(int a, int b){
     return a*b;   
    }
}

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

Input value for num1:
6
Input value for num2:
9
The Multiplication is: 54

 

Multiply two numbers in using constructor

Multiplication of two numbers using constructor with user input.

Program 3

// Multiplication of two numbers in Java
//  Multiplication using constructor with user input
import java.util.Scanner;
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) {
        Scanner sc=new Scanner(System.in); 
        System.out.print("Input first number: "); 
        int num_1=sc.nextInt(); 
    System.out.print("Input second number: "); 
        int num_2=sc.nextInt();
    
    //create an object for class
    Mul_Cons mul=new Mul_Cons(num_1, num_2);
    
    //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

Input first number: 12
Input second number: 11
product of two numbers: 132

 

Multiply two numbers in using recursion

Multiplication of two numbers using recursion with user input.

Program 4

// Multiplication of two numbers in Java
//  Multiplication using recursion with user input
import java.util.Scanner;
class Mul_Recursion {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in); 
        System.out.print("Input first number: "); 
        int num_1=sc.nextInt(); 
    System.out.print("Input second number: "); 
        int num_2=sc.nextInt();
    int product=mul(num_1,num_2);
        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

Input first number: 10
Input second number: 9
product: 90

 

Multiply two numbers in using for loop

Multiplication of two numbers using  for loop with user input.

Program 5

// Multiplication of two numbers in Java
// Simple Multiplication using for loop
import java.util.Scanner;
class MultiplyUsingFor {
    public static void main(String[] args) {
   Scanner sc=new Scanner(System.in); 
        System.out.print("Input first number: "); 
        int num_1=sc.nextInt(); 
    System.out.print("Input second number: "); 
        int num_2=sc.nextInt();
  int result=0;
  for(int i=0; i<num_2; i++){
  result+=num_1;
  } 
        System.out.println("Product: "+result);
    }
}

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

Input first number: 10
Input second number: 5
Product: 50

 

Similar post

C++ program to multiplication of two numbers using 6 ways

C program to multiplication of two numbers using 6 ways

JavaScript program to multiplication of two numbers using 4 ways

PHP multiplication of two numbers

PHP multiplication of two numbers using function

 

Pascal code to multiplication 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