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

Tutoriel de base Java

Contrôle de flux Java

Java tableau

Java orienté objet (I)

Java orienté objet (II)

Java orienté objet (III)

Gestion des exceptions Java

Java Liste (List)

Java Queue (file d'attente)

Java Map

Java Set

Entrée et sortie Java (I/O)

Lecteur Java/Writer

Autres sujets Java

Le programme Java multiplie deux nombres flottants

Java example complete set

Dans ce programme, vous apprendrez à multiplier deux nombres flottants en Java, à stocker le résultat et à l'afficher à l'écran.

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 stored in variables first and second separately.

Note that we have 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 result of multiplying first and second in a new float variable product.

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

Java example complete set