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
    • Related

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

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes