Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {

    public static String declensionByNumber(int number, String[] words) {
        int wordIndex = 2;

        if (words.length != 3) {
            return null;
        }

        int num = Math.abs(number) % 100;
        int numX = num % 10;

        if (num > 10 && num < 20) {
            wordIndex = 2;
        } else if (numX > 1 && numX < 5) {
            wordIndex = 1;
        } else if (numX == 1) {
            wordIndex = 0;
        }

        return words[wordIndex];
    }
}