首页 > 代码库 > 简单的java程序通过对话框输出 计算加减乘除运算(运算方法可选择)
简单的java程序通过对话框输出 计算加减乘除运算(运算方法可选择)
import javax.swing.JOptionPane; // import class JOptionPanepublic class Addition { public static void main( String args[] ) { 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 mul ,sub,div; // 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 numbers from type String to type int number1 = Integer.parseInt( firstNumber ); number2 = Integer.parseInt( secondNumber ); // add the numbers sum = number1 + number2; mul = number1*number2; sub = number1-number2; div = number1/number2; String a; a=JOptionPane.showInputDialog("please choose formula mode sum sub mul div"); // display the results if(a.equals("+")) JOptionPane.showMessageDialog( null, "The sum is " + sum, "Results", JOptionPane.PLAIN_MESSAGE ); if(a.equals("-")) JOptionPane.showMessageDialog( null, "The sum is " + sub, "Results", JOptionPane.PLAIN_MESSAGE ); if(a.equals("*")) JOptionPane.showMessageDialog( null, "The sum is " + mul, "Results", JOptionPane.PLAIN_MESSAGE ); if(a.equals("/")) JOptionPane.showMessageDialog( null, "The sum is " + div, "Results", JOptionPane.PLAIN_MESSAGE ); System.exit( 0 ); // terminate the program }}
简单的java程序通过对话框输出 计算加减乘除运算(运算方法可选择)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。