In this tutorial you will learn about the Java Program to Multiply two Floating Point Numbers and its application with practical example.
Java Program to Multiply two Floating-Point Numbers
In this tutorial, we will learn to create a program that will multiply two Floating-Point Numbers in programming.
Prerequisites:-
Before starting with this tutorial, we assume that you are the best aware of the following Java programming topics:
- Operators in Java Programming.
- Basic Input and Output function in Java Programming.
- Basic Java Programming.
Program Description:-
As we all know, the integer, float, or double value in Java. First, we will take the input from the user in integer format. Secondly, we will multiply the numbers with the help of the arithmetic operator “*”. The numbers are the most useful terminology in any programming language.
With the help of this program, we can take input and Multiply Two Numbers.
Algorithm to multiply the numbers:-
1 2 3 4 5 6 7 |
1. Declaring the variables for the program. 2. Taking the input numbers from the user in float number format. 3. Multiply the numbers and storing it in a variable. 4. End program. |
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// Java Program to multiply Two Numbers import java.util.Scanner; public class IntData {//Creating the class for the program in public type //Body of Main function of the program public static void main(String[] args) { //Declaring the required variable for the program. //Integer type variable to hold number value. // Creates a reader instance which takes // input from standard input - keyboard float fno,sno,multiply; //Scanner is imported from the import package Scanner reader = new Scanner(System.in); //Taking the input from the user System.out.print("Enter first number: "); // nextInt() reads the next integer from the keyboard fno = reader.nextInt(); //Taking the input from the user System.out.print("Enter Second number: "); // nextInt() reads the next integer from the keyboard sno = reader.nextInt(); //Multipling to numbers from the input. multiply = fno*sno; // println() prints the following line to the output screen //Using the System.out.println(); System.out.println("Multiply of numbers is : " + multiply); } } |
Output:-
In the above program, we have first initialized the required variable.
- fno = it will hold the input number float value from the user.
- sno = it will hold the input number float value from the user.
- multiply = it will hold the multiply value of the two numbers.
Taking input numbers from the user.
Calculating the multiply of two numbers.
Printing the output.