Java Program to Multiply Two Numbers

Write a Java Program to Multiply Two Numbers with an example. In this programming language, there is an arithmetic (*) operator to multiply two or more numbers, and we will use the same to get the product.

This example accepts two integer values and multiplies those numbers using the arithmetic (*) operator. Next, the println statement will print the product of those values output.

package SimpleNumberPrograms;

import java.util.Scanner;

public class MultiplyTwoNumbers {
	private static Scanner sc;

	public static void main(String[] args) {
		int Number1, Number2, product;
		sc = new Scanner(System.in);
		
		System.out.print("Enter the First integer Value =  ");
		Number1 = sc.nextInt();

		System.out.print("Enter the Second integer Value = ");
		Number2 = sc.nextInt();
		
		product = Number1 * Number2;
		System.out.println("\nProduct of the two integer values = " + product);
	}
}
Java Program to Multiply Two Numbers

Java Program to Multiply Two Numbers using functions

In this example, the productofTwo function accepts two double values and returns the multiplication of those two. Within the main program, we call the productofTwo function to return the product of the given two numbers.

package SimpleNumberPrograms;

import java.util.Scanner;

public class MultiplyTwoNumbers2 {
	private static Scanner sc;

	public static void main(String[] args) {
		double Number1, Number2, product;
		sc = new Scanner(System.in);
		
		System.out.print("Enter the First =  ");
		Number1 = sc.nextDouble();

		System.out.print("Enter the Second = ");
		Number2 = sc.nextDouble();
		
		product = productofTwo(Number1, Number2);
		System.out.println("\nProduct of two float values = " + product);
	}
	
	public static double productofTwo(double a, double b) {
		return a * b;
	}
}
Enter the First =  19.5
Enter the Second = 33.2

Product of two float values = 647.4000000000001