[Java]
* Start the program header annotation.
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: Calculator
* Author: Xue Guangchen
* Completion date: January 1, September 22, 2011
* Version No.: x1.0
* Description of tasks and Solutions
* Input description:
* Problem description: implements a calculator. The user inputs two operands and one operator (+,-, *,/, and %) from the keyboard. The system automatically completes the calculation.
* Program output:
* End the comment in the program Header
*/
Package xue.com;
Public class Calculator {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
Double number = 0;
String number1 = Console. readLine ();
String op = Console. readLine ();
String number2 = Console. readLine ();
Double num1 = Double. parseDouble (number1 );
Double num2 = Double. parseDouble (number2 );
If (op. equals ("+ "))
{
Number = op1 (num1, num2 );
}
Else if (op. equals ("-"))
{
Number = op2 (num1, num2 );
}
Else if (op. equals ("*"))
{
Number = op3 (num1, num2 );
}
Else if (op. equals ("/"))
{
Number = op4 (num1, num2 );
}
Else
{
System. out. println ("invalid character entered ");
Return;
}
System. out. println (num1 + op + num2 + "=" + number );
}
Public static double op1 (double num1, double num2)
{
Return num1 + num2;
}
Public static double op2 (double num1, double num2)
{
Return num1-num2;
}
Public static double op3 (double num1, double num2)
{
Return num1 * num2;
}
Public static double op4 (double num1, double num2)
{
Return num1/num2;
}
}
Running result: