Java Zero Format ZeroRemover(String[] a)

Here you can find the source of ZeroRemover(String[] a)

Description

Zero Remover

License

Open Source License

Declaration

public static String[] ZeroRemover(String[] a) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String[] ZeroRemover(String[] a) {

        if (NeedRemove(a)) {
            for (int i = 0; i < a.length; i++) {
                String aString = a[i];
                aString = aString.substring(0, aString.length() - 1);
                if (aString.endsWith("."))
                    aString = aString.substring(0, aString.length() - 1);
                a[i] = aString;/*from w ww .j  a  va  2s.c o  m*/
            }
        } else
            return a;

        // second pass
        if (NeedRemove(a)) {
            for (int i = 0; i < a.length; i++) {
                String aString = a[i];
                aString = aString.substring(0, aString.length() - 1);
                if (aString.endsWith("."))
                    aString = aString.substring(0, aString.length() - 1);
                a[i] = aString;
            }
        } else
            return a;

        // 3rd  pass
        if (NeedRemove(a)) {
            for (int i = 0; i < a.length; i++) {
                String aString = a[i];
                aString = aString.substring(0, aString.length() - 1);
                if (aString.endsWith("."))
                    aString = aString.substring(0, aString.length() - 1);
                a[i] = aString;
            }
        } else
            return a;

        return a;

    }

    /**
     * Determin: should 0 be remove?
     * @return formatted string 
     */
    public static boolean NeedRemove(String[] a) {

        int kk = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i].indexOf(".") > -1 && a[i].endsWith("0"))
                kk++;
        }
        if (kk == a.length)
            return true;
        return false;

    }
}

Related

  1. zeroOrMore(String... patterns)
  2. zeroOut(byte[] array)
  3. ZeroPoleFilter(float In[], int In_idx, float ZeroCoef[], float PoleCoef[], int PoleCoef_idx, int lengthInOut, int orderCoef, float Out[], int Out_idx)
  4. zeroPrefix(String str, int width)
  5. zeroPrepend(long num, int digits)
  6. zeros(int n)
  7. zeros(int size)
  8. zerosInt(int len)
  9. zeroString(int length)