消息框四则运算

Posted wxdbk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了消息框四则运算相关的知识,希望对你有一定的参考价值。

 

 

 

 

源代码

import javax.swing.JOptionPane;  // import class JOptionPane

 

public class Addition1 {

 

    public static void main(String[] args)

    {

        //

        String firstNumber,fuhao,  secondNumber;     

        int number1,          // first number to add

        number2,            // second number to add

       fuhao1;              //fuhao1 to add;

        double  sum, subtract,multiply,chu;

  // read in first number from user as a string

  firstNumber =JOptionPane.showInputDialog( "Enter first integer" );

  // read in second number from user as a string

  secondNumber =JOptionPane.showInputDialog( "Enter second integer" );

  // read in operational character from user as a string

  fuhao=JOptionPane.showInputDialog("Enter yusuanfu:(1+ 2- 3* 4/)");

  number1 = Integer.parseInt( firstNumber );

  number2 = Integer.parseInt( secondNumber );

  fuhao1=Integer.parseInt( fuhao );

  sum = (double)number1 + number2;

  subtract=(double)number1 - number2;

  multiply=(double)number1*number2;

  chu=(double)number1/number2;

  switch(fuhao1)

     {

     case 1:  JOptionPane.showMessageDialog(null, "两数相加等于 " + sum, "Results",JOptionPane.PLAIN_MESSAGE );break;

     case 2:  JOptionPane.showMessageDialog(null,"两数相减等于"+subtract,"Result",JOptionPane.PLAIN_MESSAGE);break;

     case 3:  JOptionPane.showMessageDialog(null,"两数相乘等于"+multiply,"Result",JOptionPane.PLAIN_MESSAGE);break;

     case 4:   JOptionPane.showMessageDialog(null,"两数相除等于"+chu,"Result",JOptionPane.PLAIN_MESSAGE);break;

     default: System.exit( 0 ); 

 

     }

          System.exit( 0 );   // terminate the program

    }

 

}

结果截图

 

 

 

以上是关于消息框四则运算的主要内容,如果未能解决你的问题,请参考以下文章

来自不同数据框的列的数学运算

JS 文本框加法运算保留2位小数

课堂Java小程序(加减乘除与验证码)

单击运算符时如何清除文本框以输入新值?

熊猫数据框:在进行涉及两个数据框的算术运算时如何在多个索引级别上进行匹配

使用 scala 使用布尔运算折叠火花数据框中的列