Java Program to Multiply Two Numbers

Write a Java Program to Multiply Two Numbers with an example. This example accepts two integer values and multiplies those numbers. 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.

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