用js写水仙花数

...js
 
//输入一个三位数,水仙花数就是个位的三次方+十为的三次方+百位的三次方之和等于本身
console.log('请输入一个三位数:');
let a = readline.question();
if (a > 100 && a <= 999) {
if (parseInt(a / 100) ** 3 + parseInt(a % 100 / 10) ** 3 + parseInt(a % 10) ** 3 == a) {
console.log(parseInt(a));
console.log('是水仙花数:');
} else {
console.log('不是水仙花数:');
}
}else{
console.log('非法数字');
}
....
 

猜你喜欢

转载自www.cnblogs.com/yangkaiming/p/9060141.html