Java Program to Multiply Two Floating Point Numbers

Write a Java program to multiply two floating point numbers and display the result. In this example, we declared two floating point numbers, first and second, with values 2.7f and 6.8f, respectively. Next, we used the third variable to hold or store the multiplication result of the two.

package NumPrograms;

public class MultiplyTwoFloats1 {

	public static void main(String[] args) {
		
		float first = 2.7f;
		float second = 6.8f;
		
		float third = first * second;
		
		System.out.println("Product of two Floating Point Numbers = " + third);
	}
}
Java Program to Multiply Two Floating Point Numbers

This Java program allows entering two floating point numbers and prints the multiplication result.

package NumPrograms;

import java.util.Scanner;

public class MultiplyTwoFloats2 {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter the First Floating Point Number =  ");	
		float first = sc.nextFloat();
		
		System.out.print("Enter the Second Floating Point Number =  ");
		float second = sc.nextFloat();
		
		float third = first * second;
		
		System.out.println("Product of two Floating Point Numbers = " + third);
	}
}
Enter the First Floating Point Number =  11.98
Enter the Second Floating Point Number =  13.76
Product of two Floating Point Numbers = 164.8448

In this example, the multiplicationofTwo function accepts two floating point numbers and returns the multiplication or product of them.

package NumPrograms;

import java.util.Scanner;

public class MultiplyTwoFloats3 {
	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter the First =  ");	
		float first = sc.nextFloat();
		
		System.out.print("Enter the Second =  ");
		float second = sc.nextFloat();
		
		float third = multiplicationofTwo(first, second);
		
		System.out.println("Product of two Floating Point Numbers = " + third);
	}
	
	public static float multiplicationofTwo(float a, float b) {
		return a * b;
	}
}
Enter the First =  22.5
Enter the Second =  33.98
Product of two Floating Point Numbers = 764.55