HDOJ 2051 Bitset

Problem Description
Give you a number on base ten,you should output it on base two.(0 < n < 1000)

Input
For each case there is a postive number n on base ten, end of file.

Output
For each case output a number on base two.

Sample Input
1
2
3

Sample Output
1
10
11

题意:把输入的十进制数转化为二进制数

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int n=sc.nextInt();
            int[] a=new int[50];
            int i=0;
// if(n==0)
// a[0]=0;
            while(n>0){
                a[i++]=n%2;
                n=n/2;
            }
            for(int j=i-1;j>0;j--){
                System.out.print(a[j]);
            }
            System.out.println(a[0]);
        }
    }

}

你可能感兴趣的:(HDOJ 2051 Bitset)