Java Array Divide div(String[] X)

Here you can find the source of div(String[] X)

Description

div

License

Apache License

Declaration

static public String div(String[] X) 

Method Source Code

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

public class Main {
    static public String div(String[] X) {
        String[] newstring = new String[X.length];
        String pop = "";
        int i;//from ww w  .  j a  v  a 2 s  .c o m
        int M = 0;
        newstring[M] = X[0];

        for (i = 1; i < X.length; i++) {
            if (X[i] == "/") {
                double a = Double.parseDouble(X[i - 1]);
                double b = Double.parseDouble(X[i + 1]);

                if (X[i - 1].startsWith("+"))
                    newstring[M] = "+" + Double.toString(a / b);
                else if (X[i + 1].startsWith("-") & X[i - 1].startsWith("-"))
                    newstring[M] = "+" + Double.toString(a / b);
                else
                    newstring[M] = Double.toString(a / b);

                X[i + 1] = Double.toString(a / b);
                i++;
            } else {
                if (X[i] != "/" || X[i + 1] != "/")
                    M++;
                newstring[M] = X[i];
            }
        }

        for (int ii = 0; ii < newstring.length; ii++) {
            if (newstring[ii] != null)
                pop += newstring[ii];
        }

        return pop;
    }
}

Related

  1. div(float[] nums, float n)
  2. div(float[] nums, int n)
  3. div(float[] nums, int n)
  4. div(float[] values, float divisor)
  5. div(int[]... vectors)
  6. div_one(double[][] A)
  7. divide(double[] a, double sum)
  8. divide(double[] a, double v)
  9. divide(double[] a, double[] b)