嘿,所以我在我的大学里学习了我的第一个cs课程,并且在java中讲授了它。我无法将十进制转换为二进制。我似乎能够得到正确的输出,但它以相反的顺序,我不知道如何把它放在正确的顺序,这里是我到目前为止编码,在Java中将十进制转换为二进制有逆转顺序的问题
import java.util.*;
public class lab6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a decimal number to convert to binary: ");
int x = input.nextInt();
int y;
String y1="";
while(x!=0){
y=x%2;
x=x/2;
y1 = Integer.toString(y);
System.out.print(y1+" ");
}
}
}