答案是2到10还是0到10? [英] Is the answer from 2 to 10 or from 0 to 10?

查看:86
本文介绍了答案是2到10还是0到10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sololearn上有人建议:想打印前5个偶数吗?在JS中,答案是这样的:



var x;

for(x = 0; x< = 10; x + = 2){

document.write(x +);

}



我是什么尝试过:



发布问题的人输出为2 4 6 8 10,但是当我尝试时,它是0 2 4 6 8 10 ??

解决方案

从技术上讲,你们两个都不对:零是偶数 - 奇偶校验 - 维基百科 [ ^ ] - 所以前五个偶数是0,2,4,6,8。



所以他的解决方案是错误的 - 你的也是如此! :笑:

Someone on sololearn suggested this: "Want to print the first 5 even numbers?" in JS, and the answer was like this:

var x;
for(x=0;x<=10;x+=2){
document.write(x+" ");
}

What I have tried:

Output was 2 4 6 8 10 for the guy who posted the question, but when I tried it, it was 0 2 4 6 8 10??

解决方案

Technically, neither of you are right: zero is an even number - Parity of zero - Wikipedia[^] - so the "First five even numbers" are 0, 2, 4, 6, 8.

So his solution is wrong - and so is yours! :laugh:


这篇关于答案是2到10还是0到10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆