;

Java Program to Multiply two Floating Point Numbers


Tutorialsrack 19/04/2021 Java

In this Java program, you will learn how to Multiply two Floating-Point Numbers in Java and store the output and show it on the screen.

Java Program to Multiply two Floating-Point Numbers

Java Program to Multiply two Floating-Point Numbers
//Java Program to Multiply two Floating Point Numbers

public class JavaPrograms {

	public static void main(String[] args) {

		float first = 2.5f;
		float second = 2.0f;

		float product = first * second;

		System.out.println("The product is: " + product);

	}
}
Output

The product is: 5.0

Understand the Program

In the above program, we have two floating-point numbers 2.5f and 2.0f stored in variables first and second respectively.

Notice, we have used f after the numbers. This ensures the numbers are floating-point numbers, otherwise they will be assigned - type double.

first and second are then multiplied using the * operator and the output is stored in a new float variable named product.

Finally, the Output stored in the variable product is printed on the screen using println() function.


Related Posts



Comments

Recent Posts
Tags