Java Program to Multiply Two Numbers

Write a Java Program to Multiply Two Numbers with an example. This Java example accepts two integer values and multiplies those numbers. Next, the println statement will print the product of those two numbers.

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 1

In this Java 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 integer Value =  ");
		Number1 = sc.nextDouble();

		System.out.print("Enter the Second integer Value = ");
		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 integer Value =  19.5
Enter the Second integer Value = 33.2

Product of two float values = 647.4000000000001