重点:for循环嵌套 --- j和i的值互换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> var none=[1,5,3,2,99,88,0,4] for(var i=0;i<none.length;i++){ for(var j=i+1;j<none.length;j++){ if(none[i]>none[j]){ var arr=none[i] none[i]=none[j] none[j]=arr }}} document.write(none); </script> </body> </html>
时间: 2024-10-06 18:59:30