October 4, 2012 / IST / Language.

Write a program to add two two number in JAVA

import javax.swing.JOptionPane;
public class MP3
{
 public static void main(String args[])
 {
  String n1=JOptionPane.showInputDialog("Enter the 1 st number.");
  String n2=JOptionPane.showInputDialog("Enter the 2 nd number.");
  double a,b,c;
  a=Double.parseDouble(n1);
  b=Double.parseDouble(n2);
  c=a+b;
  String message=String.format("the sum of the entered two numbers is %.2f",c);
  JOptionPane.showMessageDialog(null,message);
 }
}