???
package phrase1;import java.io.*;
public class Stringcalcul {
public static void main(String args[])throws IOException{
String teststr;
BufferedReader buf;
String A=null;
String B=null;
float numA,numB,result;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("please input:");
teststr=buf.readLine();
char[] testchar=teststr.toCharArray();
char[] oper={'+','-','*','/'};
for(int i=0;i<testchar.length;i++){
switch(testchar[i]){
case '+':
for(int j=0;j<i;j++){
Character a=new Character(testchar[j]);
A=a.toString();
}
for(int j=i+1;j<testchar.length;j++){
Character b=new Character(testchar[j]);
B=b.toString();
}
numA=Float.parseFloat(A);
numB=Float.parseFloat(B);
result=numA+numB;
System.out.println(teststr+"="+result);
break;
}
}
}
}
编译通过了,但是运行的结果有时对,有时错