private static final Map<Integer, Integer> encodings =
new HashMap<Integer, Integer>();
public static void printDigit(int digit) {
int code = encode(digit);
String.format("%7s", Integer.toBinaryString(code))
.replace(' ', '0').toCharArray();
lightSegment(bits[0] == '1', " _ \n", " \n");
lightSegment(bits[5] == '1', "|", " ");
lightSegment(bits[6] == '1', "_", " ");
lightSegment(bits[1] == '1', "|\n", " \n");
lightSegment(bits[4] == '1', "|", " ");
lightSegment(bits[3] == '1', "_", " ");
lightSegment(bits[2] == '1', "|\n", " \n");
private static void lightSegment(boolean on, String onValue, String offValue) {
System.out.print(on ? onValue : offValue);
catch (InterruptedException e) {
private static int encode(int digit) {
return encodings.containsKey(digit) ? encodings.get(digit) : 0x00;
public static void main(String[] args) throws Exception {
Scanner inr = new Scanner(System.in);