Java - Write code to return a letter for a integer in the alphabet using tenary operator.

Requirements

Write code to return a letter for a integer in the alphabet using tenary operator.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        int i = 42;
        System.out.println(toString(i));
    }/*w  ww.  jav  a2  s. c  o m*/

    /**
     * This method returns a letter for a integer in the alphabet.
     * 
     * @param i
     *            the integer
     * @return the letter which represents the number.
     */
    public static String toString(int i) {
        return i > 0 && i < 27 ? "" + (char) (i + 'A' - 1) : null;
    }
}

Related Exercise