Java Program to Multiply Two Numbers - The Coding Shala
Home >> Java Programs >> Multiply Two Numbers
Other Posts You May Like
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
- Java Program to Swap two Numbers
- Count Negative Numbers in Sorted Matrix
- How to Reverse a String in Java
- Java Program to find Sum of Digits of a Number
- Add Two Numbers in Java
Comments
Post a Comment