String s = "12+45+33+5+89";
计算表示式的值
有几个加号不确定
如何算,需要代码学习。。谢谢
计算表示式的值
有几个加号不确定
如何算,需要代码学习。。谢谢
解决方案 »
- BufferedWriter的write一次写多行
- The method getPartNum() is undefined for the type UserDaoImpl
- 急,struts2遇到的Error filterStart问题
- select {0} from {1} where 1=1
- webwork 小问题
- struts + hibernate怎样在页面中显示查处的数据
- dom4j写文件出错
- struts如何在主页加载时自动调用分页的Action?
- tomcat为什么会出现这种窗口,晕阿
- 我有一个问题,希望大虾给予解决。
- 求一个正则表达式
- struts+spring+hibernate 的问题
然后转成int型运算
String s = "12+45+33+5+89";
String[] nums = s.split("\\+");
Integer sum = 0;
for(String num : nums)
sum += Integer.parseInt(num);
System.out.println( "" + sum);
String s = "+12+23+34";
String[] tempStr = s.trim().split("[+]");
Double sum = 0.00;
for (int i = 0; i < tempStr.length; i++) {
sum += Double.parseDouble(tempStr[i].equals("")?"0.00":tempStr[i]);
}
System.out.println(sum);
}
Matcher matcher = ptn.matcher("12+45+33+5+89");
int total = 0;
while(matcher.find()){
total += Integer.parseInt(matcher.group());
}
System.out.println(total);
http://sourceforge.net/projects/jep/