HDOJ 2051 Bitset

2021-01-20 16:18:39 浏览数 (1)

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

就是将一个十进制的数按二进制输出。 JAVA中直接调用Integer.toBinaryString(int i); 以二进制(基数 2)无符号整数形式返回一个整数参数的字符串表示形式。

代码语言:javascript复制
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();

            System.out.println(Integer.toBinaryString(n));

        }


    }

}

0 人点赞