将数字转换为二进制
package com.db.eduk;
import java.util.Scanner;
public class changeTo2
{
public static void main(String args[])
{
int n;
Scanner scan = new Scanner(System.in);
System.out.println("请输入要转换为二进制的数字");
n = scan.nextInt();
int r;
int i=0;
int[] a=new int[10];
do
{
if(n%2==1)
{
r=1;
}
else
{
r=0;
}
a[i]=r;
n=n/2;
i++;
}while(n>0);
System.out.print("转换后:");
for(int j=i-1;j>=0;j--)
{
System.out.print(a[j]);
}
System.out.println();
}
}