Codeforcoding

Program to multiply of two floating-point numbers in Java

Program to multiply of two floating-point numbers in Java

In this tutorial, we will discuss the concept of Program to multiply of two floating-point numbers in Java

In this topic, we are going to learn how to multiply two floating-point numbers using the multiplication operator in Java language

Program to multiply of two floating-point numbers in Java
Multiply of two floating-point numbers

What is multiplication

The multiplication is a method of combining a group of equal size. The multiplication is an arithmetic operation inverse of division

It is one of the four basic operation of arithmetic calculation others being addition,subtraction,division

The multiplication of two  numbers means, it is the operation one number is combining within another using multiply(*) operator.

 

The answer of a multiplication operation is called as “product”

 

Program to multiply of two floating-point numbers in Java

Program to find product of two  numbers

The program calculates the product of the given numbers using multiplication operator

Program 1

//Multiply two float numbers in Java
public class MultipleCalcTwo{
public static void main(String args[]){
float num1=2.5f;
float num2=3.0f;
//declare and initialize float variables
float result=num1*num2;//calculate the multiplication
System.out.println("Multiplication of "+num1+" and "+num2+" is:"+result);
}
}

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

Multiplication of 2.5 and 3.0 is :7.5

 

Program to find product of two numbers-Takes input from the user

The program allows the user to enter two floating-point numbers and then it calculates the multiplication of the given numbers using multiplication operator

Program 2

//Multiply two float numbers in Java
import java.util.*;
public class MultipleCalcTwofloat{
public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    //scanner class for input
System.out.println("Please Enter the first float number ");
float num1=sc.nextFloat();
System.out.println("Please Enter the second float number ");
float num2=sc.nextFloat();

float result=num1*num2;//calculate the multiplication
System.out.println("Multiplication of "+num1+" and "+num2+" is:"+result);
//display the output
}
}

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

Case 1

Please Enter the first float number
3.5
Please Enter the second float number
4.0
Multiplication of 3.5 and 4.0 is : 14.0

 

Case 2

Please Enter the first float number
6.5
Please Enter the second float number
10.6
Multiplication of 6.5 and 10.6 is : 68.9

 

Suggested for you

Operator in Java

Data types and variable in Java

 

Similar post

Find product of two numbers using method in Java

Find product of two numbers using recursion in Java

Multiply two numbers in C language

Multiply two numbers in C++ language

Multiply two numbers in Python language

Multiply two numbers in Java language

 

Multiply of two floating-point numbers in Java

Multiply of two floating-point numbers in C

Multiply of two floating-point numbers in C++

Multiply of two floating-point numbers in Python

 

Python exercise to Divide of two integer numbers
Multiplication of two floating point numbers in C
Exit mobile version