【发布时间】:2014-07-12 09:43:25
【问题描述】:
我给自己做了一个计算器:
import java.io.*;
public class Jcal_00_b2 {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
int a;
a = 0;
int b;
b = 0;
int res = 0;
String c;
String men;
BufferedReader ra = new BufferedReader(new InputStreamReader (System.in));
BufferedReader rb = new BufferedReader(new InputStreamReader (System.in));
BufferedReader rc = new BufferedReader(new InputStreamReader (System.in));
BufferedReader rmen = new BufferedReader(new InputStreamReader (System.in));
System.out.println("Jcal 0.0 b2.....type start to add type help for help and credits.");
men= rmen.readLine();
if(men.equals("")){
System.out.println("Give input please");
men= rmen.readLine();
}else if(men.equals("start")){
System.out.println("Type first number");
a=(int) ra.read();
System.out.println("Type Second number");
b=(int) rb.read();
System.out.println("Type operation (*,/,+,-)");
c=rc.readLine();
if(c.equals("+")){
res=a+b;
}else if(c.equals("-")){
res=a-b;
}else if(c.equals("*")){
res=a*b;
}else if(c.equals("-")){
res=a/b;
}
System.out.println("result:" +res);
System.out.println("You gave input: \n 1st no.="+a+"\n 2nd no.="+b );
}else if(men.equals("help")){
System.out.print("first type start to start the calc.\n then input first number, input second number then input the operator. \n the operator symbols are as follows:\n + for addition \n - for subtraction \n * for multiplication \n / for division ");
}
}
}
当我运行它时,它会显示以下输出:
Jcal,一个计算器.....键入开始添加类型帮助以获得帮助和学分。
开始
输入第一个数字
1
输入第二个数字
1
类型操作(*,/,+,-)
*
结果:2401
您提供了意见:
第 1 号=49
第 2 号=49
我做错了什么?
【问题讨论】:
标签: java calculator