Java Program To Multiply Two Floating Point Numbers
- May 09, 2020
- by
Java Program To Multiply Two Floating Point Numbers
In this Java Program, we perform multiplication of two floating point number.
Logic : double c = double a * double b
Step 1 : Import java.util.Scanner.
Step 2 : Ask the user to enter the first number by using System.out.print method.
Step 3 : Store the user entered number in the variable num1.
Step 4 : Ask the user to enter the second number by using System.out.print method.
Step 5 : Store the user entered number in the variable num2.
Step 6 : Close the Scanner to avoid memory leak.
Step 7 : Calculate the product of the two numbers by using * operator and store the product in the variable product.
Step 8 : Display the result by using System.out.print.
Program :
import java.util.Scanner;
public class Multiply2
{
public static void main(String[] args)
{
//This reads the input provided by user using keyboard
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number:");
//This method reads the number provided using keyboard
double num1 = sc.nextDouble();
System.out.print("Enter second number:");
double num2 = sc.nextDouble();
//Closing Scanner after the use
sc.close();
//Calculating product of two numbers
double product = num1*num2;
//Displaying the multiplication result
System.out.println("Output:"+product);
}
}
Output:
Enter First Number : 1.5
Enter Second Number : 2.5
Output: 3.75
For execution of the same do visit my YouTube Channel:


0 comments:
Post a Comment