public class MultiplyTwoNumbers { public static void main(String[] args) { float a = 7.5f; 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 a and b respectively.
Notice, we have used f after the numbers. This ensures the numbers are float, otherwise they will be assigned - type double.
a and b are then multiplied using the * operator and the result is stored in a new float variable c.
Finally, the result c is printed on the screen using println() function.