How can get the possible 3 digit combination from a number having more than 3 digits in java

java

Solution

Here some example:

public class Combination {

    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder("5278");
        String str;
        int lastIndex;

        if(builder.length() % 2 == 0) {
            lastIndex = builder.length() / 2;
        } else {
            lastIndex = builder.length() / 2 + 1;
        }
        str = builder.toString() + builder.toString().substring(0, lastIndex);

        for (int i = 0; i < builder.length(); i++) {
            System.out.println(str.substring(i, i + 3));
        }
    }
}

Update more simpler way than above (based on conversation with veredesmarald)

public class Combination {

    public static void main(String[] args) {
        char[] digits = Integer.toString(123).toCharArray();
        for (int i = 0; i < digits.length; i++) {
            System.out.println("" + digits[i] + digits[(i + 1) % digits.length] + digits[(i + 2) % digits.length]);
        }
    }
}

Problem

I/p: 5278 Desired o/p: 527,278,785,852 (I manually did this). but if number is large then its a problem. Note: Output should be in such way that no repeated combination.(i.e in above combination there is a number 527 its enough and I don't want it's possible combination 257 or 725, etc in output, How can I do this? Any clue? EDIT:One important thing input digits are unique.To be more clear at any time input cant have the value like 1123 0r 3455.

Original source