Write a java program to multiply two floating point numbers
Java program to multiply two floating point numbers
In the below program, we have two floating - point numbers 3.4f and 1.5f stored in variables first and second respectively.
Notice, we have used f after the numbers. This ensures the numbers are float, otherwise they will be assigned typed double.
first and second are then multiplied using the * operator and the result is stored in a new float variable product.
Finally, the result product is printed on the screen using println() function.
- Program:
public class MultiplyTwoNumbers {
public static void main(String[] args) {
float first = 3.4f;
float second = 1.5f;
float product = first * second;
System.out.println("The product is: " + product);
}
}
- Output:
The product is: 5.1
0 comments