Java String Pluralize plural(int number, String form1, String form2, String form3)

Here you can find the source of plural(int number, String form1, String form2, String form3)

Description

This method return plural form of word based on int value.

License

LGPL

Parameter

Parameter Description
number Int value
form1 First form of word (i == 1)
form2 Second form of word (i > 1 && i < 5)
form3 Third form of word (i > 10 && i < 20)

Return

string

Declaration

public static String plural(int number, String form1, String form2, String form3) 

Method Source Code

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

public class Main {
    /**/*w ww. j  a  va2 s  .  c  o  m*/
     * This method return plural form of word based on int value.
     *
     * @param number Int value
     * @param form1  First form of word (i == 1)
     * @param form2  Second form of word (i > 1 && i < 5)
     * @param form3  Third form of word (i > 10 && i < 20)
     * @return string
     */
    public static String plural(int number, String form1, String form2, String form3) {
        int n1 = Math.abs(number) % 100;
        int n2 = number % 10;
        if (n1 > 10 && n1 < 20)
            return form3;
        if (n2 > 1 && n2 < 5)
            return form2;
        if (n2 == 1)
            return form1;
        return form3;
    }
}

Related

  1. plural(int amount)
  2. plural(int count, String word, String ending)
  3. plural(int nb)
  4. plural(int size, String name)
  5. plural(String arg)
  6. plural(String objectName)
  7. plural(String singular)