Here you can find the source of divide(String m)
static public String[] divide(String m)
//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; } }