Java Program to find the Product of Two Numbers

The example below shows how to take two integers as an input from the user using Scanner and multiply them and display the final result on the screen in Java.

Before that, if you do not about the operators in Java, click the link below and learn about it.


Java program to find the Product of Two Numbers:

//product of two numbers

 import java.util.Scanner;

 public class ProductOfTwoNumbers 
 {
    public static void main(String[] args) 
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter first number: ");

        // reads the input number
        int num1 = scan.nextInt();
        
        System.out.print("Enter second number: ");
        int num2 = scan.nextInt();

        // Closing Scanner after the use
        scan.close();
        
        // product of two numbers
        int product = num1*num2;
        
        // Displaying the result
        System.out.println("Product of two numbers is: "+product);
    }
 }

Output:

 Enter first number: 7
 Enter second number: 7
 Product of two numbers is: 49