Java Program to Multiply two Floating Point Numbers

To understand this example, you should have the knowledge of the following Java programming topics:


Example: Multiply Two Floating-Point Numbers

public class MultiplyTwoNumbers {

    public static void main(String[] args) {

        float first = 1.5f;
        float second = 2.0f;

        float product = first * second;

        System.out.println("The product is: " + product);
    }
}

Output

The product is: 3.0

In the above program, we have two floating-point numbers 1.5f and 2.0f stored in variables first and second respectively.

Notice, we have used f after the numbers. This ensures the numbers are float, otherwise they will be assigned - type double.

first and second are then multiplied using the * operator and the result is stored in a new float variable product.

Finally, the result product is printed on the screen using println() function.

Did you find this article helpful?