Java program to multiply two numbers
- Home
- Calculations
- Java program to multiply two numbers
- On
- By
- 0 Comment
- Categories: Calculations, multiply
Java program to multiply two numbers
Java program to multiply two numbers
In this tutorial, we will discuss the Java program to multiply two numbers.
We will learn how to multiply two integer numbers
Multiply two integer numbers
Program 1
public class Multiply_Two_num{ public static void main(String args[]){ int num1=34,num2=45,product;//variable declaration product=num1*num2;//multiplication of numbers System.out.println("The product of given two numbers is: "+product); //display the result } }
When the above code is compiled and executed, it produces the following results
The multiplication of given two numbers is: 1530
This is a simple Java program to find the product of two integer numbers.
In the above program, we declared two different integer values such as 34 and 45 stored in variables num1, num2 respectively.
Then, we can find the product of given numbers using the * operator
finally, we could display the result on the screen using display statements in Java.
Multiply two integer numbers – get input from the user
import java.util.Scanner; public class Multiply_Two_num1{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); // create scanner object System.out.println("Enter the first number: "); int num1=sc.nextInt(); //this method reads value for num1 providing by user System.out.println("Enter the second number: "); int num2=sc.nextInt(); //this method reads value for num2 providing by user sc.close();//closing the scanner class int product=num1*num2;//calculating product of two numbers System.out.println("The product of numbers: "+product); //display the multiplication result } }
When the above code is compiled and executed, it produces the following results
Enter the first number: 12 Enter the second number: 23 the product of numbers: 276
Multiply two floating point numbers – get input from the user
import java.util.Scanner; public class Multiply_Two_num2{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); // create scanner object System.out.println("Enter the first number: "); double num1=sc.nextDouble(); //this method reads value for num1 providing by user System.out.println("Enter the second number: "); double num2=sc.nextDouble(); //this method reads value for num2 providing by user sc.close();//closing the scanner class double product=num1*num2;//calculating product of two numbers System.out.println("The product of given numbers: "+product); //display the multiplication result } }
When the above code is compiled and executed, it produces the following results
Enter the first number: 23.43 Enter the second number: 12.34 The product of given numbers: 289.1262
This is a simple Java program to find the product of two floating point numbers.
In the above program, we declared two different floating point values such as 23.43 and 12.34 stored in variables num1, num2 respectively.
Then, we can find the product of given numbers using the * operator
finally, we could display the result on the screen using display statements in Java.
Similar post
C++ program to multiply two numbers using function
Java program to multiply two numbers using method
Python program to multiply two numbers using function
C# program to multiply two numbers using function
PHP program to multiply two numbers using function
C program to multiply two numbers
C++ program to multiply two numbers
Java program to multiply two numbers
Python program to multiply two numbers
C# program to multiply two numbers
PHP program to multiply two numbers
JavaScript program to multiply two numbers
Calculate the total of array elements in Java
Calculate the total of array elements in C
Calculate the total of array elements in C++
Java program to calculate sum of array elements
C program to calculate sum of array elements
Java Program to calculate average of array
C Program to calculate average of array
Java Program to calculate average of odd and even numbers in an array
Java Program to calculate average of odd and even numbers
C Program to calculate average of odd and even numbers in an array
C Program to calculate average of odd and even numbers
C++ Program to calculate average of odd and even numbers in an array
C++ Program to calculate average of odd and even numbers
Data types and variable in Java
Find product of two numbers using recursion in Java