你这个字符串是不是只有一个"+"号?
如果只有一个,那太简单了
public class STest {
  public static void main(String[] args) {
    try {
      String str = "22+44";
      String operator = "+";
      int i = str.indexOf(operator);
      String a = str.substring(0,i);
      String b = str.substring(i+1);
      System.out.println(a);
      System.out.println(b);
      System.out.println(operator);
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}

解决方案 »

  1.   

    当然,上面那段代码最好放在一个try……catch()块中,因为如果字符串中没有"+" 号,就会出错的说
      

  2.   

    用StreamTokenizer类进行字符串分割很方便。具体看JDK文档 :)
      

  3.   

    StringTokenizer st=new StringTokenizer(str,"+");
    if(st.hasMoreTokens()){
                            a=st.nextToken();
    }
    if(st.hasMoreTokens()){
                            c=st.nextToken();
    }
      

  4.   

    1)String s="12*23";
       String a,b,operator;
       String temp="";
       String numberstring="0123456789.";
       Vector v=new Vector();
       a=b=operator="";
       int flag=0;
       
       for(int i=0;i<s.length();i++){
         temp=s.substring(i,i+1);
         if (numberstring.indexOf(temp)!=-1){
           a=a.concat(temp);
         }
         else {
          if (a.length()!=0) v.add(a);
            v.add(temp);
            a="";
         }
       }
       if (a.length()!=0) v.add(a);
       System.out.println(v.toString());
    2)String a,b,operator;
       String temp="";
       String numberstring="0123456789.";
       a=b=operator="";
       int flag=0;
       
       for(int i=0;i<s.length();i++){
         temp=s.substring(i,i+1);
         if (numberstring.indexOf(temp)!=-1){
           if (operator.length()==0) a=a.concat(temp);
           else b=b.concat(temp);
         }
         else {
          if (b.length()==0) operator=operator.concat(temp);
            else break;
         }
       }
       System.out.println(a+"  "+b+"  "+operator);
      

  5.   

    xmvigour(微电) (  )  get it right
      

  6.   

    String s="12*(23+100)-75/78";
       String a,b,operator;
       String temp="";
       String numberstring="0123456789.";//多一个点是处理小数用的
       String operatorstring="+-*/()";//这里可以增加你所要的操作符
       Vector v=new Vector();
       a=b=operator="";
       int flag=0;
       
       for(int i=0;i<s.length();i++){
         temp=s.substring(i,i+1);
         if (numberstring.indexOf(temp)!=-1){
           a=a.concat(temp);
         }
         else if(operatorstring.indexOf(temp)!=-1) {
          if (a.length()!=0) v.add(a);
            v.add(temp);
            a="";
         }
         else{
            if (a.length()!=0) v.add(a);
            a="";
         }
       }
       if (a.length()!=0) v.add(a);
       System.out.println(v.toString());
      

  7.   

    String numberstring="0123456789.E";//你要当作数字的都放这里
      

  8.   

    String numberstring="0123456789.E-";//你要当作数字的都放这里
      

  9.   

    String numberstring="0123456789.E";//你要当作数字的都放这里
    还是这个正确
    -就当作减号处理 效果一样!
      

  10.   

    其实就是词法分析嘛
    用BNF写几个式子
    然后就是老一套了嘛
      

  11.   

    package test;//如果是很多个相加,比如 str = "12+23+12+123+";,可以如下分割:
    public class ST {
      public static void main(String[] args) {
        try {
          int i = 0;
          int j=0;
          String str = "12+23-12*123/12";
          String[] operator = {"+","-","*","/"};
          String[] block = new String[str.length()];//定义足够长
          for(i=0;i<block.length;i++) {
            block[i] = "";
          }
          int max = 0;
          i=0;
          while(max!=-1) {
            max = -1;
            int[] num = new int[operator.length];//num = 4;
            for(j=0;j<num.length;j++) {
              num[j] = str.indexOf(operator[j]);
            }
            for(j=0;j<num.length;j++) {
              if(j==0) {
                max = num[0];
              }
              else {
                if(num[j]!=-1) {
                  if(max==-1) {
                    max = num[j];
                  }
                  else {
                    if(num[j]<max) {
                      max = num[j];
                    }
                  }
                }
              }
            }
            if(max!=-1) {
              block[i] = str.substring(0,max);
              str = str.substring(max+1);
              /*//如果不需要将运算符号也算进来,可以将下面的循环注释掉
              for(j=0;j<num.length;j++) {
                if(num[j]==max) {
                  i++;
                  block[i] = operator[j];
                }
              }
              //*/
              i++;
            }
            else {
              block[i] = str;
              break;
            }
          }
          for(i=0;i<block.length;i++) {
            if(!block[i].equals("")) {
              System.out.println(block[i]);
            }
          }    }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
      

  12.   

    括符等什么的,只要将它添加进String[] operator = {"+","-","*","/"};
    里面就行
      

  13.   

    String numberstring="0123456789.E";//当作数字的字符
       String operatorstring="+-*/()";//这里可以增加你所要的操作符
       
    负号当作减号处理