Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Vusi Mbonani
Added: May 16, 2021 1:53 PM
Views: 503
Tags: no tags
  1.  
  2. package addition;
  3.  
  4. import javax.swing.JOptionPane;
  5.  
  6. public class Addition {
  7.  
  8.     public static void main(String[] args) {
  9.         //Declare local variables.
  10.         String inputOne, inputTwo;
  11.         int valueOne, valueTwo, sum;
  12.        
  13.         //Get the input from the user using show input dialog box.
  14.         inputOne = JOptionPane.showInputDialog(null,"Enter first value: ");
  15.         //Get the input from the user using show input dialog box.
  16.         inputTwo = JOptionPane.showInputDialog(null,"Enter second value: ");
  17.         //Converting a String to an integer using Type wrapper Class.
  18.         valueOne = Integer.parseInt(inputOne);
  19.         //Converting a String to an integer using Type wrapper Class.
  20.         valueTwo = Integer.parseInt(inputTwo);
  21.          //Performing addition.
  22.          sum = valueOne + valueTwo;
  23.          //displaying the sum of two integer numberss using the show message dialog.
  24.          JOptionPane.showConfirmDialog(null, "The Sum of Two Numbrs is "+sum);
  25.        
  26.     }
  27.    
  28. }
  29.