参考代码:
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 人评分
Hello, world! (C语言代码)浏览:1202 |
【亲和数】 (C语言代码)浏览:542 |
求圆的面积 (C语言代码)浏览:1272 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:572 |
简单的a+b (C语言代码)浏览:817 |
printf基础练习2 (C语言代码)浏览:748 |
Cylinder (C语言描述+详细分析)浏览:3266 |
矩阵乘方 (C语言代码)浏览:1031 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:683 |
简单的a+b (C语言代码)浏览:512 |