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

2024-11-21 11:41:51
推荐回答(1个)
回答1:

最简陋的版本...

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));
}
}