String ss = "(4*(100+0.8)-1)";
char [] str = new char[ss.length()];//如果定义String 数组也可以
for(int i = 0; i < ss.length(); i ++)
{
str[i] = ss.charAt(i);
}
char [] str = new char[ss.length()];//如果定义String 数组也可以
for(int i = 0; i < ss.length(); i ++)
{
str[i] = ss.charAt(i);
}
class integer_to_byte
{
public static void main(String[] args) throws Exception
{
String ss = "(4*(100+0.8)-1)";
byte[] buf=new byte[20];
buf=ss.getBytes();
}
}
import java.util.*String str = "(4*(100+0.8)-1)";
...
...
public List split(str) {
List result = new ArrayList();
Pattern p = Pattern.compile("(\\(|\\)|[\\*+-/]|\\d+(\\.\\d+)?)");
Matcher m = p.matcher(str);
while (m.find()){
item = m.group(1);
System.out.println(item);//test only
result.add(item);
}
return result;
}输出结果:(
4
*
(
100
+
0.8
)
-
1
)
public List split(String str) {
...
}^_^
方法一:
String ss = "(4*(100+0.8)-1)";
char [] str = new char[ss.length()];//如果定义String 数组也可以
for(int i = 0; i < ss.length(); i ++)
{
str[i] = ss.charAt(i);
}
方法二:
String ss = "(4*(100+0.8)-1)";
byte[] buf=new byte[20];
buf=ss.getBytes();
以上两种都不是数学表达式能够实现的结果。其实我是想写一个有个性的计算器,效果如下
计算器:http://lkjsp.go.nease.net/stackAdd/
但是我在通过substring()方法,来拆分数学表达式如:(4*(100+0.8)-1),在算法上开消太大了
想请各位高手,想一个开消小点的算法,以便大家一起学习与交流…………
public List split(String str) {
List result = new ArrayList();
Pattern p = Pattern.compile("(\\(|\\)|[\\*+-/]|\\d+(\\.\\d+)?)");
Matcher m = p.matcher(str);
while (m.find()) {
String item = m.group(1);
System.out.println(item); //test only
result.add(item);
}
return result;
}
int l;
if((l = t.countTokens())>0)
{
String[] sa = new String[l];
for(int i=0;i<sa.length;i++)
{
sa[i] = t.nextToken();
System.out.println(sa[i]);
}
}
class integer_to_byte
{
public static void main(String[] args) throws Exception
{
String ss = "(4*(100+0.8)-1)";
byte[] buf=new byte[ss.length()];
buf=ss.getBytes();
}
}