Find Sum of Two Integer by Creating Dialog box in Java.
Source code
Main Class:
package find.sum;
public class FindSumTest {
public static void main(String[] args)
{
Input i = new Input();
i.scanInput();
}
}
Input Class:
package find.sum;
import javax.swing.JOptionPane; ///for show Dialog box you have to import this
public class Input
{
public void scanInput()
{
int a,b;
String A,B;
A = JOptionPane.showInputDialog("Enter The 1st Integer Value: "); ///scan as string,int not possible
B =JOptionPane.showInputDialog("Enter The 2nd Integer Value: ");
a = Integer.parseInt(A); ///convert string to Int
b = Integer.parseInt(B);
JOptionPane.showMessageDialog(null,"The Sum of "+a+" & "+b+" is: " +(a + b),"Result",JOptionPane.INFORMATION_MESSAGE); ///show output
}
}
Add your comment