慕粉1603412396
var a = [1,2,3,4,5,6,7,8,9]; var arr = new Array(); var old = new Array(); for(var i =0 ; i<a.length;i++){ if(a[i]%2==0){ arr.push(a[i]); }else{ old.push(a[i]); } } var temp; for(i=0; i<arr.length;i++){ for(var j=i+1;j<arr.length;j++){ if(arr[i]>arr[j]){ temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } for(i=0; i<old.length;i++){ for(j=i+1;j<old.length;j++){ if(old[i]>old[j]){ temp=old[i]; old[i]=old[j]; old[j]=temp; } } } document.write("数组中的最大奇数是:"+old[old.length-1]); document.write("数组中的最大偶数是:"+arr[arr.length-1]); document.write("它们的和为:"+(arr[arr.length-1]+old[old.length-1]));