//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.11 on page 85
//  Recursive Function that converts decimal to hexadecimal

public class Pr0411
{ public static void main(String[] args)
  { int n ;
    for ( int count = 0 ; count < 10 ; count++ )
    {  n =  (int)(Math.round(Math.random()*1000));
       System.out.println("hexadecimal("+n+") = " + hexadecimal(n) );
    }  
  }
  public static String hexadecimal(int n)
  {  String s = hex(n%16);
     if (n < 16) return s ;               // basis
     return  hexadecimal(n/16) + s;  // recursion
  }
  static String hex(int n)
  { if ( n < 10 ) return "" + n ;
    else return (char)('A' + n - 10);
  }
}
