简单的JAVA加法小程序!完成给分!

来源:百度知道 编辑:UC知道 时间:2024/05/14 02:42:04
要有GUI界面.让用户输入要相加的数字个数,(比如输入3,就计算三个数相加的得数),然后让用户依次输入三个数的值(重复输入1个数的值时覆盖上次输入的值).最后加个按钮,点击后计算出得数!
帮忙用JAVA写这样的一个程序!给追80分(就80分了!)!谢谢了...

import javax.swing.JOptionPane;
public class ADD
{
public static void main(String[] arg)
{
String num;
int sum=0;

String countString;
int count;
countString =JOptionPane.showInputDialog("输入要相加的数字个数");
count=Integer.parseInt(countString);
if(count==0)
System.exit(0);
for(int n=0;n<count;n++)
{
num=JOptionPane.showInputDialog("请输入第"+(n+1)+"数字");
sum=Integer.parseInt(num)+sum;
}

JOptionPane.showMessageDialog(null,
"相加的结果"+sum,"结果",JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}

楼主看看行不行?不行的话给我提示,我再改!