Here you can find the source of minCharsForCriteria(final int length, final int criteria)
Parameter | Description |
---|---|
length | string length |
criteria | percentage of characters |
static int minCharsForCriteria(final int length, final int criteria)
//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; } }