100-999的水仙花数;
for(var i = 100; i < 1000; i++){
var gw = i % 10;
var sw = parseInt(i / 10) % 10;
var bw = parseInt(i / 100);
var sum = gw * gw * gw + sw * sw * sw + bw * bw * bw;
if (sum == i){
document.write(i + "<br>");
}
}
共有200元钱,球拍15元一个,球3元一个,水2元一瓶,每样至少买一个,有多少种可能?
var num = 0;
for(var i = 0; i <= 12; i++){
for(var j = 0; j <= 60; j++){
for(var k = 0; k <= 90; k++){
var jiage = i * 15 + j * 3 + k * 2;
if(jiage == 180){
document.write("球拍:" + i +"个,球:"+j+"个; 水:" + k +"<br>");
num = num + 1;
}
}
}
}
document.write("总共有:"+num+"种可能");
共有100文钱 公鸡2文钱一只,母鸡一文钱一只,小鸡半文钱一只,每样至少买一只,共有多少种可能?
方法一
var num = 0;
for(var i = 0; i <= 48; i++){
for(var j = 0; j <= 96; j++){
for(var k = 0; k <= 193; k++){
var jiage = i * 2 + j * 1 + k * 0.5;
var zhishu = i + j + k;
if(jiage == 96.5 && zhishu == 97){
document.write("公鸡:" + i +"只,母鸡:"+j+"只; 小鸡:" + k +"<br>");
num = num + 1;
}
}
}
}
document.write("总共有:"+num+"种可能");
方法二
var num = 0;
for(var i = 1; i < 50; i++){
for(var j = 1; j < 100; j++){
for(var k = 1; k < 200; k++){
var jiage = i * 2 + j * 1 + k * 0.5;
var zhishu = i + j + k;
if(jiage == 100 && zhishu == 100){
document.write("公鸡:" + i +"只,母鸡:"+j+"只; 小鸡:" + k +"<br>");
num = num + 1;
}
}
}
}
document.write("总共有:"+num+"种可能");
break 跳出循环 continue 跳过循环;
0-100能被7整除的数
0-100和7有关的数
for(var i = 0; i <= 100; i++){
var sw = parseInt(i / 10) % 10;
if(i%7 == 0 || i%10 == 7 || sw == 7){
document.write(i+"<br>");
}
}