程序代码:
<html> <head> <title>b</title> </head> <body> <script language="javascript" type="text/javascript"> <!-- var arry = new Array(3); for (var i=0; i<arry.length; ++i){ arry[i] = new Array(4); } var enter; do{ enter = String(prompt("输入12个数并以空格分开", "")).split(' '); }while (12 != enter.length && (function(){alert("确认输入"); return true;})()); //alert(enter.toString()); for (var i=0; i<arry.length; ++i){ for (var j=0; j<arry[i].length; ++j){ arry[i][j] = parseInt(enter[i*4 + j]);//将字符串转化为整形 } } Print(); for (var i=0; i<arry.length; ++i){ Sort(arry[i]); } Print(); function Print(){ document.write("<p>"); for (var i=0; i<arry.length; ++i){ for (var j=0; j<arry[i].length; ++j){ document.write(arry[i][j]); document.write(" "); } document.write("<br/>"); } document.write("</p>"); } function Sort(v){ if (!v.length){ }else{ var max = {data:v[0], index:0}; for (var i=0; i<v.length; ++i){ if (max.data < v[i]){ max.data = v[i]; max.index = i; } } v[max.index] = v[0]; v[0] = max.data; } } --> </script> </body> </html>