首页 > 技术文章 > 求最大值

lowbrid 2014-01-14 16:41 原文

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
   #show{
    width:150px;
 height: 280px;
 margin:0 auto;
 background:#2c2c2c;
 color:red;
 text-align:center;
   }
</style>
<title>循环</title>
    <script type="text/javascript" >
    var n = parseInt(window.prompt("请输入n的值",0));
    var i = 1;
    var max = parseInt(prompt("请输入第"+i+"数",0));
    while(i<n)
    {
     i++;
     num = parseInt(prompt("请输入第"+i+"数",0));
     if(max<num){
       max=num;
     }
    }
  
    document.write("<div id='show'>"+max+"</div>");

 
 </script>
</head>
<body>
 
</body>
</html>

推荐阅读