This is the syntax highlighted version of BinaryConverter.java.
/*************************************************************************
* Compilation: javac BinaryConverter.java
* Execution: java BinaryConverter N
*
* Prints out the binary representation of N.
*
* % java BinaryConverter 8
* 1000
*
* % java BinaryConverter 366
* 101101110
*
*************************************************************************/
class BinaryConverter {
static void convert(int n) {
if (n == 0) return;
convert(n / 2);
System.out.print(n % 2);
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
convert(N);
System.out.println();
}
}
Last updated: Wed Feb 11 18:10:39 EST 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.