English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this program, you will learn how to multiply two floating-point numbers in Java, store the result, and display it on the screen.
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.