Creating a multiplier application in Java

Our next application inputs two integers (whole numbers, like –22, 7 and 1024) typed by a user at the keyboard, computes the multiplication of the values and displays the result. This program uses another predefined dialog box from class JOptionPane called an input dialog that allows the user to input a value for use in the program. The program also uses a message dialog to display the multiplication of the integers. ___________________________________________________________________________________
//Creating a multiplier
// Java extension packages
 import javax.swing.JOptionPane;      // import class JOptionPane

public class Multiplier {

// main method begins execution of Java application

public static void main( String args[] )
 String firstNumber; // first string entered by user
 String secondNumber; // second string entered by user
 int number1; // first number
 int number2; // second number
 int mul; // multiplication of number1 and number2

 // read in first number from user as a String
 firstNumber = JOptionPane.showInputDialog( “Enter first integer” );

 // read in second number from user as a String
 secondNumber = JOptionPane.showInputDialog( “Enter second integer” );

// convert numbers from type String to type int
 number1 = Integer.parseInt( firstNumber );
 number2 = Integer.parseInt( secondNumber );

 // add the numbers
 mul = number1 * number2;

// display the results
 JOptionPane.showMessageDialog( null, “The multiplication is ” + mul, “Results”, JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate application

} // end method main

 } // end class Multiplier


 User Input 1

User Input 2

Multiplication output


What do you think? Please reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s