Java String Divide divide(String m)

Here you can find the source of divide(String m)

Description

divide

License

Apache License

Declaration

static public String[] divide(String m) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static public String[] divide(String m) {
        int ii = 0;

        // int x=1;
        char[] operations = new char[m.length()];
        String[] nums = new String[100];
        boolean mm = false;
        boolean mn = false;
        for (int i = 0; i < m.length(); i++) {

            operations[i] = m.charAt(i);
            if (operations[i] == '+' & mm == true) {
                nums[ii] = "-";
                mm = false;//  ww w.  j  ava 2s  .c o m
            } else if (operations[i] == '-' & mm == true) {
                nums[ii] = "+";
                mm = false;
            } else if (operations[i] == '+' & mn == true) {
                nums[ii] = "+";
                mn = false;
            } else if (operations[i] == '-' & mn == true) {
                nums[ii] = "-";
                mn = false;
            } else if (operations[i] == '/') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "/";
                ii++;
            } else if (operations[i] == '(') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "(";
                ii++;
                mn = false;
                mm = false;
            } else if (operations[i] == ')') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = ")";
                ii++;
                mn = false;
                mm = false;
            } else if (operations[i] == '%') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "%";
                ii++;
            } else if (operations[i] == 'S') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "S";
            } else if (operations[i] == '*') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "*";
                ii++;
            } else if (operations[i] == '+') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "+";
                mn = true;
            } else if (operations[i] == '-') {
                if (nums[ii] != null)
                    ii++;
                nums[ii] = "-";
                mm = true;
            } else {
                if (nums[ii] == null)
                    nums[ii] = "";
                nums[ii] += m.charAt(i);
                mm = false;
                mn = false;
            }
        }

        String[] newone = new String[ii + 1];
        for (int iii = 0; iii < ii + 1; iii++) {
            if (nums[iii] != null)
                newone[iii] = nums[iii];
        }

        return newone;
    }
}

Related

  1. div(String content, String extra)
  2. div(String second, String first)
  3. div(String text)
  4. divide(final String s)
  5. divide(Object o1, Object o2, String type)
  6. divide(String str, char c)
  7. divide(String ts, String ms)
  8. divide(String type)
  9. divideFullName(final String fullName)