【题目】Problem A.二进制数字调转

Problem A

输入数据
0-2 的 32 次方范围,化成二进制,然后逆序这个二进制序列,转换成十进制。

测试数据:
2

输出:
1

测试数据:
10

输出:
5

解答:

import java.util.Scanner;
/*
Problem A 
输入数据 0-2 的 32 次方范围,化成二进制,然后逆序这个二进制序列,转换成十进制。 
测试数据: 
2 
输出: 
1 
测试数据:
10   
输出:
5
*/
public class Test{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {
			int n = scanner.nextInt();
			String str = Integer.toBinaryString(n);
			StringBuffer stb = new StringBuffer(str);
			stb = stb.reverse();
			str = stb.toString();
			n = Integer.valueOf(str, 2);
			System.out.println(n);
		}
	}	
}
发布了233 篇原创文章 · 获赞 254 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/weixin_44485744/article/details/104975328