Java program to multiply two floating point numbers
www.igifaedit.com
Here's a Java program to multiply two floating point numbers:
public class MultiplyFloatingPointNumbers { public static void main(String[] args) { float num1 = 3.14f; float num2 = 2.5f; float product = num1 * num2; System.out.printf("%.2f * %.2f = %.2f", num1, num2, product); } }
In this program, we have two float variables num1
and num2
that represent the two floating point numbers we want to multiply. We use the *
operator to multiply them together and store the result in a float variable product
.
We then use the printf()
method to format the output with two decimal places, and print the values of num1
, num2
, and product
using the %f
format specifier. The %.2f
format specifier tells printf()
to display the floating point numbers with two decimal places.
When you run this program, it will multiply the two floating point numbers num1
and num2
, and print the result with two decimal places.