Activity 1.9.1.
guessGame(28)
guessGame(12)
guessGame(77)
guessGame(3)
public static String guessGame(int number) { if (number % 4 == 0) { return "Good guess!"; } if (number % 7 == 0) { return "Good guess!"; } return "Try again"; }
- Correct!
public static String guessGame(int number) { if (number % 4 == 0 || number % 7 == 0) { return "Good guess!"; } return "Try again"; }
- Correct!
public static String guessGame(int number) { if (number % 4 != 0 && number % 7 != 0) { return "Try again"; } return "Good guess!"; }
- Correct!
Look at the first code block. Which of the following options have the same functionality as it (i.e., they produce the same output for the same inputs)? You can check the Hint for some input examples.
public static String guessGame(int number) {
if (number % 4 == 0) {
return "Good guess!";
} else if (number % 7 == 0) {
return "Good guess!";
}
return "Try again";
}
Hint.
Hint: You can use the following test cases to compare the functionality of the code blocks.
Select all that apply.