读书人

0001+x用什么算法能做出来啊解决办法

发布时间: 2012-03-05 11:54:01 作者: rapoo

0001+x用什么算法能做出来啊
想了半天做法都很笨笨啊
例如:
0001+10=0010

0999999+2 =100001

[解决办法]
我估计是Java编译器在编译的时候直接把001转化成1了,所以运行才不会出问题。
[解决办法]
import java.lang.Integer;
class t
{
public static void main(String[] args)
{
String no = "00000001 ";
int x=10;
int re = Integer.valueOf(no).intValue();
re = re + x;
no = String.valueOf(re);
int a = no.length();
for(int i = 0; i < 8 - a ; i++){
no = "0 " + no;
}
System.out.println(no);
}
}

读书人网 >J2SE开发

热点推荐