基本方法:
public static void main(String []args) {
System.out.println("输入一个数");
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int sum;
String b="";
for(int i=a;i>=1;i/=2) {
if(i%2==0) {
sum=0;
}
else {
sum=1;
}
b=sum+b;
}
System.out.println(a+"的二进制数为");
System.out.println(b);
}
}