Java Digit From toDigit(int i)

Here you can find the source of toDigit(int i)

Description

Converts a digit to its char representation.

License

Open Source License

Parameter

Parameter Description
i the digit to be converted

Return

the char representation of i

Declaration

public static char toDigit(int i) 

Method Source Code

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

public class Main {
    /**/*from   w  w  w  .  j  a v  a2 s.c  om*/
     * Converts a digit to its {@code char} representation. The digits 0 through 9 and converted to '0' through '9',
     * and the digits 10 through 35 are converted to 'A' through 'Z'.
     *
     * <ul>
     *  <li>{@code i} must be at least 0 and no greater than 35.</li>
     *  <li>The result is between '0' and '9', inclusive, or between 'A' and 'Z', inclusive.</li>
     * </ul>
     *
     * @param i the digit to be converted
     * @return the {@code char} representation of {@code i}
     */
    public static char toDigit(int i) {
        if (i >= 0 && i <= 9) {
            return (char) ('0' + i);
        } else if (i >= 10 && i < 36) {
            return (char) ('A' + i - 10);
        } else {
            throw new IllegalArgumentException("i must be at least 0 and no greater than 35. Invalid i: " + i);
        }
    }
}

Related

  1. toDigit(final boolean bit)
  2. toDigit(final char ch, final int index)
  3. toDigit(final char ch, final int index)
  4. toDigit(final int value)
  5. toDigit(int c)
  6. toDigit(int n)
  7. toDigit(int n)
  8. toDigiTime(int Zeit)