Java Number Min Value minCharsForCriteria(final int length, final int criteria)

Here you can find the source of minCharsForCriteria(final int length, final int criteria)

Description

Identifies the number of characters in a string of a given length that match the given percentage.

License

Open Source License

Parameter

Parameter Description
length string length
criteria percentage of characters

Return

number of characters that are required to satisfy the given percentage, rounded down or up

Declaration

static int minCharsForCriteria(final int length, final int criteria) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2011-2013 Pushing Inertia
 * All rights reserved.  http://pushinginertia.com
 *
 * 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.//from   w w  w .j  a va  2s  . co  m
 */

public class Main {
    /**
     * Identifies the number of characters in a string of a given length that match the given percentage. The output is
     * equal to the rounded value of ((length * criteria) / 100).
     * @param length string length
     * @param criteria percentage of characters
     * @return number of characters that are required to satisfy the given percentage, rounded down or up
     */
    static int minCharsForCriteria(final int length, final int criteria) {
        final int i = length * criteria;
        final int remainder = i % 100;
        if (remainder >= 50)
            return (i / 100) + 1;
        return i / 100;
    }
}

Related

  1. min4(double v1, double v2, double v3, double v4)
  2. MIN4(int x, int y, int z, int a)
  3. min8(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8)
  4. MIN_MAX(int min, int mid, int max)
  5. minChar(String input)
  6. minCommonMultiple(int m, int n)
  7. minComparable(T first, T second)
  8. minCoverageEstimate(short mask)
  9. minCurveSegmentLength(String segmentTypeName)