I am making a decimal to binary program in an entry level AP computer science class. I used the decimal to binary algorithm but the program prints out the reverse of the binary string.
public static void main (String[]args) {
int n = Integer.parseInt(args[0]);
while (n>0) {
if (n%2==0) { //for even numbers
System.out.print("0");
n/=2; //
}
else {
System.out.print("1");
n--; // for odd numbers
n/=2;
}
}
}