1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> </html> <script type="text/javascript"> var a=Math.random(); document.write(a+"<br />"); a=Math.floor(Math.random()*21); document.write(a+"<br />"); a=Math.floor(Math.random()*71+20); document.write(a+"<br />"); document.write("练习1<br />"); var b=0; for(var i=1;i<=10;i++){ a=Math.floor(Math.random()*61+30); document.write(a+"<br />"); b+=a; } document.write("和等于"+b+"<br />"); document.write("练习2<br />"); var a=0,b=0,c=70; for(var i=1;i<=10;i++){ a=Math.floor(Math.random()*51+20); document.write(a+"<br />"); var d=a>b?a:b; b=d; var e=a<c?a:c; c=e; } document.write("最大值"+d+"<br />"); document.write("最小值"+e+"<br />"); document.write("练习3<br />"); var a=0,max=0,min=70; for(var i=1;i<=10;i++){ temp=Math.floor(Math.random()*51+20); document.write(temp+"<br />"); var max=temp>max?temp:max; var min=temp<min?temp:min; } document.write("最大值"+max+"<br />"); document.write("最小值"+min+"<br />"); document.write("练习3<br />"); var max=0,min=80,max_index=0,min_index=0; for(var i=1;i<=10;i++){ temp=Math.floor(Math.random()*71+10); document.write(temp+"<br />"); if(max<temp){ max=temp; max_index=i; } if(min>temp){ min=temp; min_index=i; } } document.write("最大值"+max+"<br />"); document.write("在第"+max_index+"位<br />"); document.write("最小值"+min+"<br />"); document.write("在第"+min_index+"位<br />"); </script>
|