1. 程式人生 > >用JavaScript,打印水仙花數;

用JavaScript,打印水仙花數;

java head doctype char body int utf console i++

<!DOCTYPE html> <html>
<head> <meta charset="utf-8" /> <title></title> <script> //打印水仙花數
var g, s, b; for (var i = 100; i <= 999; i++) { g = i % 10; s = parseInt(i / 10) % 10; b = parseInt(i / 100); if (g * g * g + s * s * s + b * b * b == i) { console.log(i); } } </script> </head>
<body> </body>
</html>

用JavaScript,打印水仙花數;