English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Array

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List (List)

Java Queue (queue)

Java Map collection

Java Set collection

Java Input/Output (I/O)

Java Reader/Writer

Other Java topics

Java program to multiply two floating-point numbers

Java Comprehensive Examples

In this program, you will learn how to multiply two floating-point numbers in Java, store the result, and display it on the screen.

Example: Multiplication of 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("Calculation Result: ", + product);
    }
}

When running the program, the output is:

Calculation Result: 3.0

In the above program, we have two floating-point numbers1.5f and2.0f and store them in variables first and second respectively.

Note that we used f after the number. This ensures that the number is a float, otherwise it will be assigned as a double type.

Then use multiplication*operator, and store the multiplication result of first and second in a new float variable product.

Finally, use the println() function to print the product result on the screen.

Java Comprehensive Examples