Final answer:
The subject of this question is Computer Science and it pertains to writing a method called checkVals() in Java that reads integers from input until 1 is read. The method should return true if none of the integers read before 1 are between -2000 and -1000 inclusive, and false otherwise.
Step-by-step explanation:
The subject of this question is Computer Science and it pertains to writing a method called checkVals() in Java that reads integers from input until 1 is read. The method should return true if none of the integers read before 1 are between -2000 and -1000 inclusive, and false otherwise.
To solve this problem, you can use a while loop to continuously read integers from the input using the Scanner object, and check if each integer falls within the forbidden range. If any integer falls within the range, you can set a boolean flag to false and break out of the loop.
Here's an example implementation of the checkVals() method:
public static boolean checkVals(Scanner scanner) {
boolean allAllowed = true;
while (scanner.hasNext()) {
int num = scanner.nextInt();
if (num == 1) {
break;
} else if (num >= -2000 && num <= -1000) {
allAllowed = false;
break;
}
}
return allAllowed;
}