Calculations

Java program to multiply two numbers

Java program to multiply two numbers

In this tutorial, we will discuss the Java program to multiply two numbers.

Multiplication

We will learn how to multiply two integer numbers

Multiply two integer numbers

Program 1

public class Multiply_Two_num{
public static void main(String args[]){
int num1=34,num2=45,product;//variable declaration
product=num1*num2;//multiplication of numbers
System.out.println("The product of given two numbers is: "+product);
//display the result
}

}

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

The multiplication of given two numbers is: 1530

This is a simple Java program to find the product of two integer numbers.

In the above program, we declared two different integer values such as  34 and 45 stored in variables num1, num2 respectively.
Then, we can find the product of given numbers using the * operator

finally, we could display the result on the screen using display statements in Java.

 

Multiply two integer numbers – get input from the user

import java.util.Scanner;
public class Multiply_Two_num1{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);
// create scanner object

System.out.println("Enter the first number: ");

int num1=sc.nextInt();
//this method reads value for num1 providing by user

System.out.println("Enter the second number: ");

int num2=sc.nextInt();
//this method reads value for num2 providing by user

sc.close();//closing the scanner class

int product=num1*num2;//calculating product of two numbers


System.out.println("The product of numbers: "+product);
//display the multiplication result
}

}

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

Enter the first number:
12
Enter the second number:
23
the product of numbers: 276

 

Multiply two floating point numbers – get input from the user

import java.util.Scanner;
public class Multiply_Two_num2{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);
// create scanner object

System.out.println("Enter the first number: ");

double num1=sc.nextDouble();
//this method reads value for num1 providing by user

System.out.println("Enter the second number: ");

double num2=sc.nextDouble();
//this method reads value for num2 providing by user

sc.close();//closing the scanner class

double product=num1*num2;//calculating product of two numbers


System.out.println("The product of given numbers: "+product);
//display the multiplication result
}

}

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

Enter the first number:
23.43
Enter the second number:
12.34
The product of given numbers: 289.1262

This is a simple Java program to find the product of two floating point numbers.

In the above program, we declared two different floating point values such as 23.43 and 12.34 stored in variables num1, num2 respectively.
Then, we can find the product of given numbers using the * operator

finally, we could display the result on the screen using display statements in Java.

 

Similar post

C++ program to multiply two numbers using function

Java program to multiply two numbers using method

Python program to multiply two numbers using function

C# program to multiply two numbers using function

PHP program to multiply two numbers using function

 

C program to multiply two numbers 

C++ program to multiply two numbers

Java program to multiply two numbers 

Python program to multiply two numbers 

C# program to multiply two numbers 

PHP program to multiply two numbers 

JavaScript program to multiply two numbers 

 

Calculate the total of array elements in Java

Calculate the total of array elements in C

Calculate the total of array elements in C++

Java program to calculate sum of array elements

C program to calculate sum of array elements

Java Program to calculate average of array

C Program to calculate average of array

Java Program to calculate average of odd and even numbers in an array

Java Program to calculate average of odd and even numbers

C Program to calculate average of odd and even numbers in an array

C Program to calculate average of odd and even numbers

C++ Program to calculate average of odd and even numbers in an array

C++ Program to calculate average of odd and even numbers

 

Operator in Java

Data types and variable in Java

Find product of two numbers using recursion in Java

 

 

C program to the sum of two numbers
C program to multiply two numbers
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…

1 day 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