two Java problems

two Java problems

题目
two Java problems
Question:Write a program which asks the user two numbers and the calculation (+, - , * or /) to be performed. The program shall print the calculation as well as the answer. Take care of the situation the divisor being zero.
My answer:
import java.util.Scanner;
public class task5 {
public static void main(String[] args) {
Scanner stdin=new Scanner(System.in);
System.out.println("Please enter a number ");
double a=stdin.nextDouble();
System.out.println("Please enter a number again");
double b=stdin.nextDouble();

String readEnter=stdin.nextLine();

System.out.println("Please enter a calculation(+-*/)");
String c=stdin.nextLine();

stdin.close();

String P="+", M="-", MU="*",D="/";
double result=0;

char cc=c.charAt(0);

if(cc.equals(P)){
result=a+b;
System.out.println("The result for "+a+c+b+" is "+res
答案
1、String P="+",M="-",MU="*",D="/";double result=0;char cc=c.charAt(0);if(cc.equals(P)){result=a+b;System.out.println("The result for "+a+c+b+" is "+result);}你cc是char,而P是String.所以把 char cc=c.ch...
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.