Fare丶梦


私信TA

用户名:126913199

访问量:41123

签 名:

等  级
排  名 236
经  验 6119
参赛次数 0
文章发表 50
年  龄 22
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:





注意事项:

eclipse完美运行,,但是在这显示答案错误(仅供参考)



参考代码:

import java.util.Scanner;


public class Main {

        public static void calcuator(int a,int b,String N){

                char[] array = N.toCharArray();

                switch (array[0]) {

                        case '+':

                                System.out.println(a+b);

                                break;

                        case '-':

                                System.out.println(a-b);

                                break;

                         case '*':

                                 System.out.println(a*b);

                                 break;

                         case '/':

                                 float A = Float.valueOf(a);

                                 float B = Float.valueOf(b);

                                 System.out.println(A/B);

                                 break;

                         case '%':

                                 System.out.println(a%b);

                                 break;

                         default:

                                 break;

                }

        }

        public static void main(String[] arg) {

                Scanner sc = new Scanner(System.in);

                int a = sc.nextInt();

                int b = sc.nextInt();

                String N = sc.next();

                calcuator(a, b, N);

        }

}


 

0.0分

0 人评分

  评论区

哥们 ,题目说的输入是整数, 不能转化为float;
2017-12-24 22:45:19
  • «
  • 1
  • »