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);
}

解决方案 »

  1.   

    import java.io.*;
    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();
      }
    }
      

  2.   

    import java.util.regex.*;
    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
    )
      

  3.   

    should be 
    public List split(String str) {
    ...
    }^_^
      

  4.   


    方法一:
    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),在算法上开消太大了
    想请各位高手,想一个开消小点的算法,以便大家一起学习与交流…………
      

  5.   

    duracell() 的做法就可以,不过有些小错误 :)
    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;
    }
      

  6.   

    StringTokenizer t = new StringTokenizer(str,"+-*/()",true);
    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]);
    }
    }
      

  7.   

    能不能用一个流来做,用readInt(),readFloat(),readChar();
      

  8.   

    import java.io.*;
    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();
      }
    }
      

  9.   

    用两个stack来解决这个问题……