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的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点
- 小亮放学回家,他倒了一杯牛奶,先喝了1/3,接着加满果汗又喝了这杯的1/2,再加满最后把这杯饮料全喝下,那么小亮喝的牛奶多还是果汁多?为什么?(友谊提醒:请你观察小亮喝饮料过
- 填介词:Kate is good _____ singing English songs.
- 已知关于x的方程x^2+px+q=0,写出下列起情况中系数p.q满足的条件:(1)两根互为相反数.(2)两根互为倒数
- 三角形ABC中,D是BC的中心,E是AD的中心,这个三角形的面积是72平方厘米,求ABE和DCE的面积?
- 食盐在水中溶解的快慢与哪些因素有关,除了颗粒的大小,水温,是否搅拌
- 有时候,有些人对自己所处的环境及正在做的事情反而不急旁人看得清楚,这就是人们常说的——诗句
- (1)i am afraid of——(go out)at night alone
- 师者,所以传道,授业,解惑也 这句话的意思.
- 请问SEM扫描电镜中钨灯丝与场发射的同与异,及各自的优点和缺点.
- can never too的含义