/* (程序头部注释开始) </p><p>* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* 作 者: 李兆庆
* 完成日期: 2012 年 9 月 22 日
* 输入描述:
* 问题描述及输出:实现一个计算器,用户从键盘输入两个操作数和一个运算符(+、-、*、/、%),系统自动完成计算
* 程序头部的注释结束
*/
import javax.swing.JOptionPane;
public class Num {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str=JOptionPane.showInputDialog("请输入第一个操作数;");
double x = Integer.parseInt(str);
String str1=JOptionPane.showInputDialog("请输入第二个操作数;");
double y = Integer.parseInt(str1);
String str2=JOptionPane.showInputDialog("请输入操作符;");
System.out.println(x+str2+y+"="+get_result(x,y,str2));
}
public static double get_result (double x, double y, String c)
{
double result = 0;
if ( c.equals("+") )
{
result = x + y;
}
else if (c.equals("-"))
{
result = x - y;
}
else if ( c.equals("*"))
{
result = x * y;
}
else if ( c.equals( "/"))
{
result = x / y;
}
else
{
System.out.println("请您输入合法运算符!");
}
return result;
}
}