Showing posts with label Java Program to add two numbers. Show all posts
Showing posts with label Java Program to add two numbers. Show all posts

Monday, September 3, 2018

Program to add, subtract, multiply and divide two numbers using inputdialogbox


Follow the steps to create GUI:

Addition using Input Dialog Box









Step-1: Drag and drop four radio buttons for Add, Subtract, Multiply and Divide.

Step-2: Change the variable name of Add Radio Button to AddRadioButton.

Step-3: Double Click on Add Radio Button.

Step-4: Write the following code:


 private void AddRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        double fn=Double.parseDouble(JOptionPane.showInputDialog("Enter First Number"));
        double sn=Double.parseDouble(JOptionPane.showInputDialog("Enter Second Number"));
        double sum=fn+sn;
        JOptionPane.showMessageDialog(null, sum);
    }     

Similarly for other operations like Subtraction, Multiplication, and Division.