求3721,163,1,4832,1980,2008,68686688,9999,17173,5173,8848中最大的数
明白后,试着求一下最小数,平均数等
<html> <head> <title>求一组数中的最大数 - aspxhome.com</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <p>求3721,163,1,4832,1980,2008,68686688,9999,17173,5173,8848中最大的数</p> <p>明白后,试着求一下最小数,平均数等</p> <hr> <SCRIPT LANGUAGE="JavaScript"> <!-- function max(numlist) { var arr = numlist.split(","); var maxnum = -1000000; document.write("参与比较的数是:"+numlist); for(var i=0;i<arr.length;i++) { document.write("<br><br>当前最大数是:“"+maxnum+"”,准备要比较的数是:" + parseInt(arr[i])); if(maxnum<parseInt(arr[i])) { document.write("<br><font color=red>"+parseInt(arr[i])+" > "+maxnum+",当前最大数变成是:“"+arr[i]+"”</font>"); maxnum = arr[i]; } else { document.write("<br><font color=blue>"+parseInt(arr[i])+" < "+maxnum+",当前最大数还是:“"+maxnum+"”</font>"); } } document.write("<br><br><br><font color=#ff00ff>比较完成,最大数是:“"+maxnum+"”</font>"); return maxnum; } max("3721,163,1,4832,1980,2008,68686688,9999,17173,5173,8848") //--> </SCRIPT> </body> </html> [提示:你可先修改部分代码,再按运行]