In this Java program, you will learn how to Multiply two Floating-Point Numbers in Java and store the output and show it on the screen.
//Java Program to Multiply two Floating Point Numbers
public class JavaPrograms {
public static void main(String[] args) {
float first = 2.5f;
float second = 2.0f;
float product = first * second;
System.out.println("The product is: " + product);
}
}
The product is: 5.0
In the above program, we have two floating-point numbers 2.5f and 2.0f stored in variables first and second respectively.
Notice, we have used f after the numbers. This ensures the numbers are floating-point numbers, otherwise they will be assigned - type double.
first and second are then multiplied using the * operator and the output is stored in a new float variable named product.
Finally, the Output stored in the variable product is printed on the screen using println()
function.
Comments