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
- Visit:
Java program to swap two numbers Here
Java program to check whether a given number is even or odd Here
Java program to check whether an alphabet is vowel or consonant Here
Java program to find the largest among three numbers Here
Java program to find all roots of a quadratic equation Here
Java program to check leap year Here