码迷,mamicode.com
首页 > 编程语言 > 详细

java加减乘除消息框显示结果

时间:2015-10-07 22:49:43      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

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

public class Operation {
// An addition program


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
dif, // difference of number1 and number2
pro, //product of number1 and number2
cou; //cousuit 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 numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );

// add the numbers
sum = number1 + number2;
dif = number1 - number2;
pro = number1 * number2;
cou = number1 / number2;
// display the results
JOptionPane.showMessageDialog(null,
"和为 " + sum +"\n"+
"差 为" + dif +"\n"+
"积为" + pro+"\n"+
"商为" + cou+"\n",
"Results",
JOptionPane.PLAIN_MESSAGE );

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

}

 技术分享

java加减乘除消息框显示结果

标签:

原文地址:http://www.cnblogs.com/zuhaoran/p/4859660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!