发布网友 发布时间:2022-05-05 14:20
共2个回答
热心网友 时间:2022-04-23 08:02
交叉合并:如字符串一为:abcd 字符串二为:1234。则结果为:a1b2c3d4。
import java. util. ArrayList; import java. util. List; public class A {
public static void main(string[] args){
string a[]={"a","b","c"};
string b[]={"1","2","3"};
CombineTwoArray(a,b);
system. out. println(CombineTwoArray(a,b));
}
public static List<string>combineTwoArray(string[] first, String[] second)t List<string>outlist=new ArrayList<string>();
int index=0;
while(index< first. length && index< second. length){
outlist. add(first[ index]); outlist. add(second[ index]);
++index; if(index>=first. length){
for (int i=index;i< second. length;i++){
outlist. add(second[i]);
}
} else{
for (int i=index;i<first. length;i++){
outlist. add(first[i]);
}
return outlist;
}
}
js的写法:
<!DOCTYPE html pUBLIC"-//w3c//DTD XHTMT 1.0
Transitional//EN""http://www.w3.org/TR/xhtm11/DrD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtm1">
<head>
<title>第十五题:交叉合并字符串</title>
<style>
#form{
margin:0auto;width:500px;top:100px;height:300px;
</style>
<script type="text/javascript">
var reg="*[A-za-20-9]+$";function check(){
var strl =document.all.strl.value;var str2 =document.all.str2.value;if(str1==""){
alert(“字符串一不允许为空!");document.all.strl.focus();return;
}else if(!/^[A-2a-20-9]+$/.test(str1)){
alert("字符串一只能是数字和字母的组合");document.all.str1.focus();return;
}else if(str2==""){
alert(”字符串二不允许为空!");document.all.str2.focus();
return;
}else if(!/^[A-Za-20-9]+5/.test(str2)){
alert(“字符串二只能是数字和字母的组合");document.a1l.str2.focus();return;var string="";var font1="<font style='color:red;'>";var font2="<font style='color:blue;'>";var fontend="</font>";if(str1.1ength>=str2.1ength){
for(vari=0;i<str1.1ength;i++){
if(i< str2.length){
string +=font1+strl[i]+fontend+ font2+ str2[i]+fontend;
}else{
string+=font1+strl[il;
}else{
for(var i=0;i<str2.1ength;i++){
if(i< strl.length){
document.all.result.innerHTML=string;
</script>
</head>
<body>
<div id="form">
<center><h2>第十五题:交叉合并字符串</h2></center>
字符串1:<input type="text"id="str1"/><br/>字符串2:<input type="text"id="str2"/><br/>
<input type="button"value="交叉合并字符串”onclick="check();"/>
<br/>
<div id="result"></div>
</div>
</body></html>
string+=font1+strl[i]+fontend+font2+str2[i]+fontend;
}else{
string+=font2+str2[i]+fontend;
扩展资料:
/**
* 合并两个函数
* @param functionA 先执行
* @param functionB 执行完 functionA 后返回
* @returns {*}
*/
function mergeFunction (functionA, functionB) {
if (!functionA || !functionB) return
var merge = functionB
functionB = (function () {
merge.call(this)
functionA.call(this)
})()
return functionB = merge
}
热心网友 时间:2022-04-23 09:20
function merge(s1,s2){