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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | //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:
1 2 3 | Enter first number: 7 Enter second number: 7 Product of two numbers is: 49 |