Java Program to Multiply Two Floating Numbers

Java Program to Multiply two Floating Point Numbers

In this program, We will learn to multiply two floating point numbers in Java, store the result and display it 

Example: Multiply Two Floating Point Numbers

public class MultiplyTwoNumbers {

   public static void main(String[] args) {

        float a = 7.5f;
        float b = 2.0f;

        float c= a * b;

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

When you run the program, the output will be:

The product is: 15.0


In the above program, we have two floating point numbers 7.5f and 2.0f stored in variables and b respectively.

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

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

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

Subscribe For Daily Updates

JAVA File IO examples

JAVA Date & Time Progamming Examples

JAVA Collections

Flutter Questions
Android Questions