Java Number Negate negate(String value)

Here you can find the source of negate(String value)

Description

Compute the "negated" string, which replaces the digits (0 becomes 9, 1 becomes 8, ...

License

Apache License

Parameter

Parameter Description
value the input string; may not be null

Return

the negated string; never null

Declaration

protected static String negate(String value) 

Method Source Code

//package com.java2s;
/*/*from   ww w  .  j a  v a2  s  .c om*/
 * ModeShape (http://www.modeshape.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Compute the "negated" string, which replaces the digits (0 becomes 9, 1 becomes 8, ... and 9 becomes 0).
     * 
     * @param value the input string; may not be null
     * @return the negated string; never null
     * @see #negate(StringBuilder)
     */
    protected static String negate(String value) {
        return negate(new StringBuilder(value)).toString();
    }

    /**
     * Compute the "negated" string, which replaces the digits (0 becomes 9, 1 becomes 8, ... and 9 becomes 0).
     * 
     * @param value the input string; may not be null
     * @return the negated string; never null
     * @see #negate(String)
     */
    protected static StringBuilder negate(StringBuilder value) {
        for (int i = 0, len = value.length(); i != len; ++i) {
            char c = value.charAt(i);
            if (c == ' ' || c == '-')
                continue;
            value.setCharAt(i, (char) ('9' - c + '0'));
        }
        return value;
    }
}

Related

  1. negate(int[] ar)
  2. negate(int[] input)
  3. negate(int[] x, int Max)
  4. negate(String expr)
  5. negate(String string, String trueValue, String falseValue)
  6. negateExact(double a)
  7. negateExpression(String expression)
  8. negateInPlace(float[] in)
  9. Negation(String StartIP, String netmask)