Java Program to Multiply Two Floating Point Numbers
In this java program, you'll learn how to multiply two floating point numbers and then display the result in the console.
How to Multiply Two Floating Point Numbers in Java?
Sourcecode
/*
Author : CodersEditor.com
Program : Java Program to Multiply Two Floating Point Numbers
*/
public class Main {
public static void main(String[] args) {
float firstNumber = 25.1f;
float secondNumber = 222.0f;
float result = firstNumber * secondNumber;
System.out.println("The result is: " + result);
}
}
Output
The result is: 5572.2
Explanation
- In this program, the two floating-point numbers are stored in the variables firstNumber and secondNumber respectively.
- Both the floating-point variables are multiplied using the * operator and the result is stored in the variable "result" and then displayed in the cosnole using System.out.println.
note
- When assigning the floating point variables , we have used f in the end to specify the value is a floating value and not double.