Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Find product of two floating point numbers in Python

Program for find product of two floating point numbers in Java

Posted on March 11, 2021March 11, 2021

Table of Contents

  • Program for find product of two floating point numbers in Java
    • Code to calculate product of two floats
      • Code to calculate product of two floating point numbers
      • Code to calculate product of two floating point numbers – using user input
      • Code to calculate product of two floating point numbers – using method

Program for find product of two floating point numbers in Java

In this article, we will discuss the concept of Program for find product of two floating point numbers in Java

In this post, we are going to learn how to write a program to calculate product of two floating point numbers using different methods in Java program.

Code to calculate product of two floats

Code to calculate product of two floating point numbers

In this code, we will calculate product of two floating point numbers using variable declaration and initialization in Java language

Program 1

public class Product_Two_Floats{
public static void main(String args[]){
float firstNum=2.5f;
float secondNum=3.4f;//float variable declaration
  
float product= firstNum * secondNum;//calculate product
       System.out.println("The product is: "+product);
//display result
}
   
}

When the above code is executed, it produces the following result

The product is: 8.5

 

Code to calculate product of two floating point numbers – using user input

In this code, we will calculate product of two floating point numbers using takes input from the user in Java language

Program 2

import java.util.Scanner;
public class Product_Two_Floats_from_input{
public static void main(String args[]){

  Scanner sc=new Scanner(System.in);
  //Ask input from the user
  System.out.println("Please Enter two floating numbers: ");
  //read the first float number
float firstNum=sc.nextFloat();
//read the second float number
float secondNum=sc.nextFloat();;

System.out.println();
float product= firstNum * secondNum;//calculate product of two floats
       System.out.println("The product is: "+product);
//display result
   
}
}

When the above code is executed, it produces the following result

Please Enter two floating numbers
2.6
3.2
The product is: 8.32

 

Code to calculate product of two floating point numbers – using method

In this code, we will calculate product of two floating point numbers using method in Java language

Program 3

import java.util.Scanner;
class ProductFloatWithmethod{
public static void main(String args[]){

    Scanner scan=new Scanner(System.in); //create a scanner object for input
System.out.print("Enter the first number: ");
float n1=scan.nextFloat();//get input from the user for num1
System.out.print("Enter the second number: ");
float n2=scan.nextFloat();//get input from the user for num2
calcFloatproduct(n1,n2);//calling the method
}

static void calcFloatproduct(float num1,float num2){//method definition
  double product=num1*num2;
System.out.print("product of"+num1+"and"+num2+" is: "+product);
  
}
}

When the above code is executed, it produces the following result

Enter the first number: 12.5
Enter the second number: 10.4
Product of 12.5 and 10.4  is: 130.0

 

Suggested for you

Data type and variable in Java

Operator in Java

Class and main method explanation in Java

Variable types in Java language

 

Similar post

Java code to product of two numbers

C code to product of two numbers

C++ code to product of two numbers

Python code to product of two numbers

 

Java code to Calculate product of two floating point numbers

C code to Calculate product of two floating point numbers

C++ code to Calculate product of two floating point numbers

Python code to Calculate product of two floating point numbers

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes