王品


私信TA

用户名:wangpin

访问量:18676

签 名:

等  级
排  名 493
经  验 4473
参赛次数 1
文章发表 41
年  龄 21
在职情况 学生
学  校 安徽师范大学皖江学院
专  业 软件工程

  自我简介:

参考代码:

import java.util.*;


public class Main {

    

    public static void main(String[] args) {

        int count=0;

        Scanner sc=new Scanner(System.in);


        while(sc.hasNext())            //读取到以文件结尾

        {

            String str1=sc.next();

            int opIndex;                     //读取'+'、'-'、' ='的下标,从而得到a b c的字符串


            if(str1.indexOf('+')!=-1)

                opIndex=str1.indexOf('+');

            else

                opIndex=str1.indexOf('-');


            int eqIndex=str1.indexOf('=');


            String astr=str1.substring(0,opIndex);           //将记录a b c的字符串转换成int

            String bstr=str1.substring(opIndex+1,eqIndex);

            String cstr=str1.substring(eqIndex+1);


            int a=Integer.parseInt(astr);

            int b=Integer.parseInt(bstr);


            int c;

            if(str1.charAt(eqIndex+1)!='?')

                c=Integer.parseInt(cstr);

            else

                continue;


            char op=str1.charAt(opIndex);

            if(op=='+'&&c==a+b)

                count++;

            if(op=='-'&&c==a-b)

                count++;

        }

        System.out.println(count);

    }

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区