Java Array to String arrayToString(int[] s)

Here you can find the source of arrayToString(int[] s)

Description

Translate an array of int-s specifying throw height into a String that uses the normal siteswap notation.

License

Open Source License

Declaration

public static String arrayToString(int[] s) 

Method Source Code

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

public class Main {
    /**/*w  w w .j  a  v  a2s  .c  om*/
     * Translate an array of int-s specifying throw height into a String that
     * uses the normal siteswap notation.
     *
     * Example:
     * arrayToString([11,9,7,5,3,1]) returns "b97531"
     */
    public static String arrayToString(int[] s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length; i++) {
            try {
                sb.append(intToChar(s[i]));
            } catch (Exception e) {
                return null;
            }
        }
        return sb.toString();
    }

    /**
     * Translate between a throw height specified as an int and it's
     * representation in the alphabet we use to denote siteswaps (0 through Z).
     *
     * Example:
     * intToChar(12) returns 'c'
     */
    public static char intToChar(int i) throws Exception {
        if (i < 0 || i > 35)
            throw new Exception("int out of bounds");
        if (i < 9)
            return (char) ('0' + i);
        else
            return (char) ('a' + i - 10);
    }
}

Related

  1. arrayToString(int[] array)
  2. arrayToString(int[] array)
  3. arrayToString(int[] array)
  4. arrayToString(int[] ary)
  5. arrayToString(int[] c, String separator)
  6. arrayToString(int[] subset)
  7. arrayToString(int[][] array)
  8. arrayToString(Object arbitraryArray)
  9. arrayToString(Object array)