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.


Also Read:

Did you find this article helpful?

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community