public static String printme(int i) {
StringBuilder mOut = new StringBuilder();
while(true) {
if(i % 2 == 1) {
mOut.insert(0, "1");
} else {
mOut.insert(0, "0");
}
i = i / 2;
if(i == 0) {
return mOut.toString();
}
}
}
For the reader: code up an integer representation without using ten else-ifs or java's automatic integer to string converters. Just append chars.
No comments:
Post a Comment