打字猴:1.700474224e+09
1700474224
1700474225 //获得表达式
1700474226
1700474227 public static String getExpStr()throws IOException{
1700474228
1700474229 System.out.print(“请输入表达式:”);
1700474230
1700474231 return(new BufferedReader(new InputStreamReader(System.in))).readLine();
1700474232
1700474233 }
1700474234
1700474235 //获得值映射
1700474236
1700474237 public static HashMap<String,Integer>getValue(String exprStr)throws
1700474238
1700474239 IOException{
1700474240
1700474241 HashMap<String,Integer>map=new HashMap<String,Integer>();
1700474242
1700474243 //解析有几个参数要传递
1700474244
1700474245 for(char ch:exprStr.toCharArray()){
1700474246
1700474247 if(ch!=’+’ && ch!=’-‘){
1700474248
1700474249 //解决重复参数的问题
1700474250
1700474251 if(!map.containsKey(String.valueOf(ch))){
1700474252
1700474253 String in=(new BufferedReader(new InputStreamReader
1700474254
1700474255 (System.in))).readLine();
1700474256
1700474257 map.put(String.valueOf(ch),Integer.valueOf(in));
1700474258
1700474259 }
1700474260
1700474261 }
1700474262
1700474263 }
1700474264
1700474265 return map;
1700474266
1700474267 }
1700474268
1700474269 }
1700474270
1700474271 其中,getExpStr是从键盘事件中获得的表达式,getValue方法是从键盘事件中获得表达式中的元素映射值,运行过程如下。
1700474272
1700474273 }
[ 上一页 ]  [ :1.700474224e+09 ]  [ 下一页 ]