Google News
logo
Java Program to Multiply two Floating Point Numbers
In the following example Java program to multiply two floating point numbers :
Program :
import java.util.Scanner;

public class MultiplyFloats {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the first floating point number: ");
        float num1 = scanner.nextFloat();

        System.out.print("Enter the second floating point number: ");
        float num2 = scanner.nextFloat();

        float product = num1 * num2;

        System.out.println("The product of " + num1 + " and " + num2 + " is " + product);
    }
}
Output :
Enter the first floating point number: 2.7
Enter the second floating point number: 3.6
The product of 2.7 and 3.6 is 9.72
In this program, we use the Scanner class to read two floating point numbers input by the user. We then multiply the two numbers together and store the result in a variable called product. Finally, we print out a message displaying the values of the two numbers and the product of the two numbers.