Friday, April 13, 2007

AddNumbers

import javax.swing.*;

public class Add2numbers{

public static void main(String[] args){
Add2numbers add=new Add2numbers();

}
public Add2numbers(){
String num1,num2,output="";
int no1,no2,sum=0;

num1=JOptionPane.showInputDialog(null,"Enter 1st to add","INPUT NO1",JOptionPane.QUESTION_MESSAGE);
num2=JOptionPane.showInputDialog(null,"Enter 2nd to add","INPUT NO2",JOptionPane.QUESTION_MESSAGE);

no1=Integer.parseInt(num1);
no2=Integer.parseInt(num2);

sum=no1+no2;

output+="first number entered is" + no1 +"\n";
output+="Second number entered is" + no2 +"\n";

JOptionPane.showMessageDialog(null,output+no1+"+"+no2+"="+sum,"sum",JOptionPane.INFORMATION_MESSAGE);

System.exit(0);
}
}

No comments: