Write a Java Program that multiplies two floating-point numbers.
Click Here to View the Solution!
public static void main(String args)
//variables of data type float are initialized //to store the numbers
;System.out.println("Numbers to be multiplied are: " + first + " " + second); // new integer product is initialized // the value is kept equal to the product of both numbers
product = first * second;
System.out.println("The product is: "
Click Here to View the Output!
Numbers to be multiplied are: 1.7 3.1 The product is: 5.27
Click Here to View the Explanation!
- In this program, Floating-point variables
secondare initialized, and
3.1fare stored in them respectively.
- It’s important to add
fafter the numbers to declare them as
floatotherwise they will be assigned type
- Another variable product is declared to store the product of the variables first and second using the
println()function prints product on console screen.