首页 > 代码库 > 一百以内十个随机数放入数组排序并打印
一百以内十个随机数放入数组排序并打印
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
一百以内十个随机数放入数组排序并打印<br />
</body>
</html>
<script>
var array=new Array()
for(var i=0;i<=9;i++)
{
array[i]=parseInt(100*Math.random());
for( var b=0;b<i;b++ )
{
if (array[i]==array[b])
{
i--;
}
}
}
//array.sort();
for(var i=0;i<9;i++)
{
for(var j=i;j<9;j++)
{
if(parseInt(array[i])>parseInt(array[j+1]))
{
var zhong =array[i];
array[i]=array[j+1];
array[j+1]=zhong;
}
}
}
for( var i=0;i<10;i++)
{
document.write(array[i]+"<br />")
}
</script>
一百以内十个随机数放入数组排序并打印