//輸出所有4位數的奇數整數,并且滿足:個位數+百位數?=?十位數+千位數,每行輸出15個數字;
???
//用下面的for語句來寫是OK的:
var?a?=?null;
var?i=1001;
var?count?=?0;//計數器
for?(i;?i?<?10000;?i++)?{
????a?=?i.toString();
????if?((+a[0])?+?(+a[2])?==?(+a[1])?+?(+a[3])?&&?(+a[3])?%?2?!=?0)?{
????????//輸出滿足條件的i
????????document.write(a?+?"??");
????????//每輸出15次就換行一次
????????count++;
????????if(count==15){
????????????document.write("<br/>");
????????????count=0;
????????}
????}
}//接下來換成while的寫法
var?a?=?1001;
var?count?=?0;//計數器
while?(a?<?10000)?{
????a?=?a.toString();
????if?((+a[0])?+?(+a[2])?==?(+a[1])?+?(+a[3])?&&?(+a[3])?%?2?!=?0)?{
????????//輸出滿足條件的i
????????document.write(a?+?"??");
????????//每輸出15次就換行一次
????????count++;
????????if?(count?==?15)?{
????????????document.write("<br/>");
????????????count?=?0;
????????}
????}
????i++;
}
//這樣寫的話,結果只輸出1001
for語句改為while的寫法出問題了,換成while的寫法只輸出1001
狂飆的蝸牛_1
2015-12-30 22:13:29