Here's a Java program to print the product of two floating-point numbers:
public class ProductOfFloats {
public static void main(String[] args) {
float num1 = 3.5f;
float num2 = 2.5f;
float product = num1 * num2;
System.out.println("Product of " + num1 + " and " + num2 + " is: " + product);
}
}
Explanation:
- We define a class called ProductOfFloats.
- In the main method, we declare two float variables num1 and num2, representing the two floating-point numbers whose product we want to find. You can modify these variables with your desired floating-point values.
- We multiply num1 and num2 to calculate their product and store it in the variable product.
- We use the System.out.println() statement to print the product to the console.
- When you run this program, it will output the product of the two floating-point numbers num1 and num2 on the console.
For the given values of num1 = 3.5 and num2 = 2.5, the output will be:
Product of 3.5 and 2.5 is: 8.75
You can modify the values of num1 and num2 in the main method to test the program with different floating-point numbers.
0 Comments