Java Program to Multiply Two Numbers - The Coding Shala

Home >> Java Programs >> Multiply Two Numbers

 In this post, we will learn how to Multiply Two Numbers in Java.

Multiply Two Numbers Java Program

We have given two integers or floating-point numbers, Write a Java program to multiply these numbers.

Example:
Input:
num1: 10
num2: 20
Output: 200

Java Program to Multiply Integers: 

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//scan the inputs
		System.out.println("Enter first Number");
		int num1 = sc.nextInt();
		System.out.println("Enter Second Number");
		int num2 = sc.nextInt();
		int result = num1 * num2;
		System.out.println("Multiplication of " + num1 +" and " + num2 +" is: " + result);
		sc.close();
	}
}

Output: 
Enter first Number
9
Enter Second Number
5
Multiplication of 9 and 5 is: 45

Java Program to Multiply floating-point Numbers: 

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//scan the inputs
		System.out.println("Enter first Number");
		double num1 = sc.nextDouble();
		System.out.println("Enter Second Number");
		double num2 = sc.nextDouble();
		double result = num1 * num2;
		System.out.println("Multiplication of " + num1 +" and " + num2 +" is: " + result);
		sc.close();
	}
}

Output: 
Enter first Number
2.5
Enter Second Number
2.5
Multiplication of 2.5 and 2.5 is: 6.25


Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.

Comments

Popular Posts from this Blog

N-th Tribonacci Number Solution - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Find Second Smallest Element in the Array - The Coding Shala

New Year Chaos Solution - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala