A simple program to ask the user to give two numbers and then the program will compute the sum and product of two numbers using JOptionPane in Java programming language.



My mobile number here in the Philippines is 09173084360.



Want to support my channel?

GCash Account

Jake Pomperada






Thank you very much for your support.
Program Listing
/* Jake Rodriguez Pomperada, MAED-IT, MIT
 * jakerpomperada@gmail.com

import javax.swing.JOptionPane;

public class add_product {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 // obtain user input from JOptionPane input dialogs

	      String one = 

	         JOptionPane.showInputDialog( "Enter first value" );

	      String two =

	          JOptionPane.showInputDialog( "Enter second value" );
	      // convert String inputs to int values for use in a calculation

	      int a = Integer.parseInt(one); 

	      int b = Integer.parseInt(two);
	      int sum = (a+b);
	      int product = (a*b);

	      // display result in a JOptionPane message dialog

	      JOptionPane.showMessageDialog( null,  "The Sum : " +  sum + "\n" 
	      + "The Product: " + product, "The Result", JOptionPane.INFORMATION_MESSAGE );


Leave a Reply

Your email address will not be published.