请求帮忙修改一段JAVA程序
输入任意2个数和运算符实现四则运算输入运算符这块不知道怎么弄求高手帮忙修改importjava.io.*;//publicclassOperatorClass{publi...
输入任意2个数和运算符 实现四则运算
输入运算符这块不知道怎么弄 求高手帮忙修改
import java.io.*;//
public class OperatorClass{
public static void main(String args[])throws IOException{
int a,b,c;
BufferedReader buf;
String str;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入a");
str = buf.readLine();
a=Integer.parseInt(str);
System.out.println("请输入b");
str = buf.readLine();
b=Integer.parseInt(str);
System.out.println("请输入运算符号");
str = buf.readLine();
char oper='c';
switch (oper) {
case '+':
System.out.println(a+"+"+b+"="+(a+b)); break;
case '-':
System.out.println(a+"-"+b+"="+(a-b)); break;
case '*':
System.out.println(a+"*"+b+"="+(a*b)); break;
case '/':
System.out.println(a+"/"+b+"="+((float)a/b)); break;
default:
System.out.println("Unknown operator!!");
}
}
} 展开
输入运算符这块不知道怎么弄 求高手帮忙修改
import java.io.*;//
public class OperatorClass{
public static void main(String args[])throws IOException{
int a,b,c;
BufferedReader buf;
String str;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入a");
str = buf.readLine();
a=Integer.parseInt(str);
System.out.println("请输入b");
str = buf.readLine();
b=Integer.parseInt(str);
System.out.println("请输入运算符号");
str = buf.readLine();
char oper='c';
switch (oper) {
case '+':
System.out.println(a+"+"+b+"="+(a+b)); break;
case '-':
System.out.println(a+"-"+b+"="+(a-b)); break;
case '*':
System.out.println(a+"*"+b+"="+(a*b)); break;
case '/':
System.out.println(a+"/"+b+"="+((float)a/b)); break;
default:
System.out.println("Unknown operator!!");
}
}
} 展开
1个回答
展开全部
//刚学的时候我也写过,我就不改啥了,指出你的错误吧,你看看哪里错了
import java.io.*;//
public class OperatorClass{
public static void main(String args[])throws IOException{
int a,b,c;
BufferedReader buf;
String str;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入a");
str = buf.readLine();
a=Integer.parseInt(str);
System.out.println("请输入b");
str = buf.readLine();
b=Integer.parseInt(str);
System.out.println("请输入运算符号");
str = buf.readLine();
///////here
c = str.charAt(0);
switch (c) {
case '+':
System.out.println(a+"+"+b+"="+(a+b)); break;
case '-':
System.out.println(a+"-"+b+"="+(a-b)); break;
case '*':
System.out.println(a+"*"+b+"="+(a*b)); break;
case '/':
System.out.println(a+"/"+b+"="+((float)a/b)); break;
default:
System.out.println("Unknown operator!!");
}
}
}
import java.io.*;//
public class OperatorClass{
public static void main(String args[])throws IOException{
int a,b,c;
BufferedReader buf;
String str;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入a");
str = buf.readLine();
a=Integer.parseInt(str);
System.out.println("请输入b");
str = buf.readLine();
b=Integer.parseInt(str);
System.out.println("请输入运算符号");
str = buf.readLine();
///////here
c = str.charAt(0);
switch (c) {
case '+':
System.out.println(a+"+"+b+"="+(a+b)); break;
case '-':
System.out.println(a+"-"+b+"="+(a-b)); break;
case '*':
System.out.println(a+"*"+b+"="+(a*b)); break;
case '/':
System.out.println(a+"/"+b+"="+((float)a/b)); break;
default:
System.out.println("Unknown operator!!");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询