Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
用户输入一个数字,并将其与计算机生成的数字进行比较...我正在尝试使用 if 语句来确定猜测与生成的数字的接近程度。
您在和else之间的链中缺少一个。diff > 50(diff <= 10) && (diff >= 6)
else
diff > 50
(diff <= 10) && (diff >= 6)
请注意,这不是问题的最佳解决方案,因为您复制了代码。与其为“under”和“over”设置两个分支,不如创建一个分支,并使用它Math.abs来计算差异。
Math.abs