在线等! 如何用递归法实现! 把一个十进制数的二进制表示中的连续的三位用另外三位换?(替换的三位与被替换的可以是任意的三位)比如 1345的二进制是 10101000001 用111换101 则变为11101000001要用递归实现!谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转换为二进制串,然后用 String.replaceAll() 替换,然后转换回数字型。--http://www.agui.googlepages.commailto: agui.cn(a)gmail.com public class JReplace { /** * @param args */ public static void main(String[] args) {String basisStr="10101010000101";jReplace(basisStr,"101","111","",0); }public static void jReplace(String basisStr,String otherStr,String replaceStr,String prefix,int index){ if(basisStr.length()-index<otherStr.length()){ System.out.println(basisStr); } else { if(basisStr.regionMatches(index, otherStr, 0, otherStr.length())){ prefix=prefix+replaceStr; index=index+otherStr.length(); } else { prefix=prefix+basisStr.charAt(index); index=index+1; } basisStr=prefix+basisStr.substring(index,basisStr.length()); jReplace(basisStr,otherStr,replaceStr,prefix,index); }}} static ArrayList的一些Bug 比比宝复试题 Java 输入输出问题 急:Linux下,java调用C++的动态库错误。在线等。。 htm如何转换成PDF 向oracle中插入图片是报错 数组排序,文本框问题? 请教一个Java代码的Socket通信的调试问题. 2003月07月06日升星,散分500!--分五天结贴之第五帖(最后一贴)。(次日凌晨零点结分) DOM请教 请教:JSP,servlet,JDBC的jar包到哪里下载? JAVA类型问题?
http://www.agui.googlepages.com
mailto: agui.cn(a)gmail.com
* @param args
*/
public static void main(String[] args) {
String basisStr="10101010000101";
jReplace(basisStr,"101","111","",0);
}
public static void jReplace(String basisStr,String otherStr,String replaceStr,String prefix,int index){
if(basisStr.length()-index<otherStr.length()){
System.out.println(basisStr);
}
else {
if(basisStr.regionMatches(index, otherStr, 0, otherStr.length())){
prefix=prefix+replaceStr;
index=index+otherStr.length();
}
else {
prefix=prefix+basisStr.charAt(index);
index=index+1;
}
basisStr=prefix+basisStr.substring(index,basisStr.length());
jReplace(basisStr,otherStr,replaceStr,prefix,index);
}
}
}