Fix the printIntAsDec method in Indenting writer to correctly handle negative values

This commit is contained in:
Ben Gruver 2011-07-15 13:22:45 -04:00
parent fadcc2dcb9
commit f119fc6db5

View File

@ -168,7 +168,11 @@ public class IndentingWriter extends Writer {
public void printIntAsDec(int value) throws IOException {
int bufferIndex = 0;
boolean negative = value < 0;
if (value < 0) {
value *= -1;
write('-');
}
do {
int digit = value % 10;
@ -177,10 +181,6 @@ public class IndentingWriter extends Writer {
value = value / 10;
} while (value != 0);
if (negative) {
write('-');
}
while (bufferIndex>0) {
write(buffer[--bufferIndex]);
}