Java—十进制转二进制

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_42623428/article/details/83181579
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

        int n=input.nextInt();

        int[] a=new int[1000];

        int cnt=0;

        while(n>0) {

        int t=n%2;

        a[cnt++]=t;

        n/=2;

        }

        for(int i=cnt-1;i>=0;i--) {

            System.out.print(a[i]);

        }

    }

}

猜你喜欢

转载自blog.csdn.net/qq_42623428/article/details/83181579