zoukankan      html  css  js  c++  java
  • 编写一个程序,用户输入两个数,求其加减乘除,并用消息框显示计算结果。

    代码:

    //an complex program

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

    public class Complex {

    public static void main(String[] args) {

    // TODO 自动生成的方法存根

    String firstNumber,     //first string entered by user

           secondNumber;    //second string entered by user

    int number1,            //first number to add

        number2,            //second number to add

        sum,                //sum of number1 and number2

        difference,         //difference of number1 and number2

        product,            //product of number1 and number2

        quotient;           //quotient of number1 and number2

    // 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 ");

    //convert number from type string to type int

    number1 = Integer.parseInt(firstNumber);

    number2 = Integer.parseInt(secondNumber);

    //add the numbers

    sum = number1 + number2;

    //difference the numbers

    difference = number1-number2;

    //product the numbers

    product = number1 * number2;

    //quotient the numbers

    quotient = number1/number2;

    //display the results

    JOptionPane.showMessageDialog(

    null,"The Sum is " + sum,"Results",JOptionPane.PLAIN_MESSAGE);

    JOptionPane.showMessageDialog(

    null,"The difference is " + difference,"Results",JOptionPane.PLAIN_MESSAGE);

    JOptionPane.showMessageDialog(

    null,"The product is " + product,"Results",JOptionPane.PLAIN_MESSAGE);

    JOptionPane.showMessageDialog(

    null,"The quotient is " + quotient,"Results",JOptionPane.PLAIN_MESSAGE);

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

    }

    }

           

  • 相关阅读:
    Android 编译笔记20191205
    react 编写 基于ant.design 页面的参考笔记
    Codeigniter项目使用phpDocumentor生成api文档
    php curl Problem with the SSL CA cert (path access rights)
    我的浏览器标签同步方案:坚果云+Floccus
    vue Inline JavaScript is not enabled. Is it set in your options?
    学习应该保留的十件事情
    ngx-moment汉化
    Quill Editor使用公式
    mac os安装多个版本的chrome
  • 原文地址:https://www.cnblogs.com/huangliping/p/4859618.html
Copyright © 2011-2022 走看看