用Java编写一个应用程序,要求利用消息对话框输入两个整数,并在信息框中显示这两个数的和与差。谢!

如题所述

第1个回答  2012-03-12
最简陋的版本...

public class Test
{

public static void main(String[] args) {
int n1 = Integer.parseInt(JOptionPane.showInputDialog("Input number 1: "));
int n2 = Integer.parseInt(JOptionPane.showInputDialog("Input number 1: "));

JOptionPane.showMessageDialog(null, "sum: " + (n1 + n2)
+ "\n" + "difference: " + (n1 - n2));
}
}
相似回答