HDOJ2051_Bitset

来源:互联网 发布:模拟人生4社交网络 编辑:程序博客网 时间:2024/06/06 07:50
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
123
Sample Output
11011
import java.util.Scanner;/** * 位集合 * 题目的意思也就是将一个十进制的数转换为二进制然后输出 * @author 逸川同学 * */public class P2051 {private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);while(scanner.hasNext()){int n = scanner.nextInt();String string = "";while(n>0){string = n%2+string;n = n/2;}System.out.println(string);}}}