Saturday, October 18, 2025
HomeLanguagesJavaJava Program to Multiply two Floating-Point Numbers

Java Program to Multiply two Floating-Point Numbers

The float class is a wrapper class for the primitive type float which contains several methods to effectively deal with a float value like converting it to a string representation, and vice-versa. An object of the Float class can hold a single float value.

The task is to multiply two Floating point numbers in Java and print their multiplication.

Approach:

  • Initialize two float type numbers.
  • Store their multiplication result in a float variable.
  • Print that results

Java




// Java Program to print Multiplication of two floating
// point Number.
 
import java.io.*;
 
class GFG {
    public static void main(String[] args)
    {
 
        // f is to ensures that numbers are float DATA TYPE
        float f1 = 1.5f;
        float f2 = 2.0f;
 
        // to store the multiplied value
        float p = f1 * f2;
 
        // to print the product
        System.out.println("The product is: " + p);
    }
}


Output

The product is: 3.0

Time complexity: O(1) it is doing constant operations
Auxiliary Space: O(1)

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS