-------------------------水仙花数:abc=a^3+b^3+c^3-------------------
----------------- 分析:可以随便写三个数(while做法)------------------------
var number=153;
var a=parseint(number/100);----------------百位--------------
var b=pareint (number %100/10);----------------十位---------
var c =number%10;-------------------个位--------------
if (number==a*a*a+b*b*b+c*c*c){-----------------a*a*a=Mach.pow(a,3)--------
console.log(number);
var number=100;
while (number<=999){
var a =parseint(number/100);
var b =parseint(number%100/10);
var c = number%10;
if (number==a*a*a+b*b*b+c*c*c{
console.log(number);
}
number++;
}
-------------------for 做法---------------
for(var number= 100;number<=999;number++){
var a =parseint(number/100);
var b =parseint(number%100/10);
var c = number%10;
if (number==a*a*a+b*b*b+c*c*c){
console.log(number);
}
}
-------------注:while和for的区别:for只是知道循坏次数,
while只知道循坏条件(到什么时候结束);