私信TA

用户名:Praguetramp

访问量:29489

签 名:

等  级
排  名 19
经  验 19962
参赛次数 0
文章发表 130
年  龄 0
在职情况 待业
学  校
专  业

  自我简介:

aura

解题思路:    整数转化为2进制串,遍历每个字符,若为1 则执行乘方操作,连接该结果串

注意事项:    注意格式

参考代码:

import java.util.Scanner;
public class Main {	
	public static void main(String []args) {
		Scanner in =new Scanner(System.in);
		int x =in.nextInt();
		String tmp = Integer.toBinaryString(x),res = x+"=";
		for(int i=0;i<tmp.length();i++) {
			if(tmp.charAt(i)=='1') {
				res=res+(int)Math.pow(2, (tmp.length()-1-i))+"+";  //字符串的连接
			}
		}
		System.out.println(res.substring(0, res.length()-1));
		in.close();
 	}
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区