Java Program to find product of two numbers
In this program, user is asked to enter two integers. Then, the product of those two integers is stored in a variable and displayed on the screen.
Algorithm:
Step 1: Start.
Step 2: Declare variables, say a and b.
Step 3: result = a * b.
Step 4: Display result.
Step 5: Stop.
Source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.util.Scanner; class Product { public static void main(String args[]) { int num1; int num2; int result; System.out.println("\n \n *** www.programmingposts.com *** \n \n"); System.out.println("<< JAVA Program to find product of Two Integers >> \n \n"); Scanner scanner = new Scanner(System.in); System.out.println("Enter first number:"); num1 = scanner.nextInt(); System.out.println("Enter Second number:"); num2 = scanner.nextInt(); result = num1 * num2; System.out.println("The product of two numbers is:" +result); } } |
Output:
C:\Users\santo\Desktop\new>javac Product.java
C:\Users\santo\Desktop\new>java Product
*** www.programmingposts.com ***
<< JAVA Program for division Two Integers >>
Enter first number: 5
Enter Second number: 6
The product of two numbers is:30