Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static int getIndexInTriangle(int n, int i, int j) {
        if (n < 0)
            throw new IllegalArgumentException("Triangle width negative");
        if (i < 0 || i >= n)
            throw new IllegalArgumentException("i = " + i + ", n = " + n);
        if (j < i || j >= n)
            throw new IllegalArgumentException("j = " + j + ", n = " + n);
        return n * i - ((i * i + i) >>> 1) + j;
    }
}