您的位置:首页 > 其它

HDOJ2051_Bitset

2017-10-09 23:01 405 查看
[align=left]Problem Description[/align]
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
[align=left]Input[/align]
For each case there is a postive number n on base ten, end of file.
[align=left]Output[/align]
For each case output a number on base two.
[align=left]Sample Input[/align]

1
2
3

[align=left]Sample Output[/align]

1
10
11
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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: