<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>网页标题</title> <meta name="keywords" content="关键字列表" /> <meta name="description" content="网页描述" /> <link rel="stylesheet" type="text/css" href="" /> <style type="text/css"></style> <script type="text/javascript"> //定义一个二数组 var arr =[ [1,2,3,4], [12,23,34,45], [16,27,38,40], ]; //定义总和的变量 var sum=0; //定义个数 var len=0; //假设最大值 var max=arr[0][0]; //假设最小值 var min=arr[0][0]; //循环父数组 for(var i=0;i<arr.length;i++){ //循环子数组 for(var j=0;j<arr[0].length;j++){ //总和 sum +=arr[i][j]; //个数 len++; //判断哪个大并赋值给max if(max<arr[i][j]){ max =arr[i][j]; } //判断哪个小并赋值给min if(min>arr[i][j]){ min =arr[i][j]; } } } document.write(‘平均值‘+sum/len+‘,最大值‘+max+‘,最小值‘+min); </script> </head> <body> </body> </html>
时间: 2024-12-08 01:26:18