Showing posts with label product of two numbers in java oop. Show all posts
Showing posts with label product of two numbers in java oop. Show all posts

Saturday, May 6, 2017

Product of Two Numbers in Java Using Object Oriented Programming

In this article I would like to share with you a program that I wrote in Java to accept two numbers and then our program will compute the product of the two given numbers using object oriented programming approach in Java. The code is very short and easy to understand.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


product.java


package demo;

import java.util.Scanner;


class product_value {
int val_1=0,val_2=0;
}

public class product {

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int product=0;
 
 product_value a = new product_value();
 product_value b = new product_value();
 
 System.out.println();
     System.out.println("PRODUCT OF TWO NUMBERS IN JAVA OOP");
     System.out.println();
     System.out.print("Enter First Value : ");
     a.val_1 = input.nextInt();
     
     System.out.print("Enter Second Value : ");
     b.val_2 = input.nextInt();
     
     product = (a.val_1 * b.val_2);
      
     System.out.println();
     System.out.print("The product of " + a.val_1 + " and " + b.val_2 + " is " + product + ".");
     input.close();
}

}