**关闭。**此题需要debugging details。目前不接受答复。
编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
2天前关闭。
Improve this question
我的代码不会输出它应该的指令:从输入中读取整数,直到读取的整数不在-20至25范围内(包括-20和25)。输出读取的整数总数,包括导致阅读停止的整数。以换行符结束。
例如:如果输入为-13 -49 -17 -16-11,则输出为:
读取的整数数:2我的代码:
import java.util.Scanner;
public class CountRead {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int inputValue;
int countRead;
inputValue = scnr.nextInt();
countRead = 0;
while ((inputValue >= -20) || (inputValue <= 25)) {
countRead++;
inputValue = scnr.nextInt();
}
System.out.println("Number of integers read: " + (countRead + 1));
}
}
1条答案
按热度按时间juud5qan1#
仔细看这段话非常仔细:
以及while语句具体要评估什么;
如果inputValue是说…
-49
,这个表达式的值是多少?真的假的?小心点!