Here you can find the source of toDigit(int i)
Parameter | Description |
---|---|
i | the digit to be converted |
public static char toDigit(int i)
//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); } } }