用消息框显示加减乘除的计算结果

源程序

import javax.swing.JOptionPane;
//JOptionPane 是有助于方便地弹出要求用户提供值或向其发出通知的标准对话框。  
//它是用来编写图形用户界面的一个类。
public class Jiajianfa {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        double n1=Integer.parseInt(JOptionPane.showInputDialog("Input number 1: "));

        double n2=Integer.parseInt(JOptionPane.showInputDialog("Input number 2: ")) ;
        //获取从JOptionPane.showInputDialog对话框中输入的值,然后转换为int类型

        JOptionPane.showMessageDialog(null,"The sum is:"+(n1+n2)

              +"\n"+"The difference is:"+(n1-n2)                                                                                   

              +"\n"+"The product is:"+(n1*n2)

              +"\n"+"The division is:"+(n1/n2));

    }
}

 

 

posted @ 2015-10-07 22:40  小么小儿郎  阅读(212)  评论(0编辑  收藏  举报